Oh - we're actually in the process of moving all docs over to this repo: https://github.com/cucumber/docs.cucumber.io
As you'll see in that README - docs in other locations will eventually be removed.
In the other slack channels you mentioned a build problem for cucumber expressions. Not sure how that is related to the docs.cucumber.io repo?
Ah it's a formatting error. I'll fix it. Still puzzled how this is related to you creating a PR for docs.cucumber.io
@Aslak Hellesøy Do you happen to have any input on what @tewksbum was trying last night? I was hitting a knowledge wall and then had to hit the hay
@gmk just pushed a fix for that eslint problem (to the cucumber/cucumber repo). If you're working on docs, please do that in the cucumber/docs.cucumber.io repo - the docs folder in cucumber/cucumber is obsolete and will soon be removed.
I am using wdio-cucumber to write my tests . Scenario: login as existing user Given the page url is "http://www.test.com" Then I expect that element "#login-form" becomes visible When I login with email "automate@test.com" and password "1234" Then I expect that element ".user-detail" becomes visible And I expect that the url is "http://www.test.com/user/automation/profile" . I want to pass variables for email and password so that each run of the test takes new value. How can I achieve this
I would say environment variables or the world parameters CLI option: https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#world-parameters
@charlierudolph - we’re wanting to update JS and Cucumber-JS on Cyber-Dojo.org , but we’re having problems loading modules. I worked on it with @jbpros a few weeks ago, but we didn’t get to a resolution. He suggested you might be able to help.
The issue is to do with global/local installs of Cucumber-JS and the interaction with ‘require’ statements.
Just yesterday I discovered the multiple interfaces that may be used with Cucumber-JS step definitions (https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/step_definitions.md). The asynchronous promise interface seems cleaner than the asynchronous callback interface. Can someone with more experience describe the pros and cons of each? I'd like to make a relatively informed decision before going too far down either path.
@gdinwiddie I personally prefer promises. To me, promises are the same as callbacks with better protection around them and a more standardized API for success / failure via then / catch. Callbacks have a common pattern of err being the first argument but there are instance where that isn't followed. Promises can also be written really nicely using async / await (which can be converted to es5 using babel).
Thanks. Promises seemed like a much cleaner solution, but I don't have much experience with cucumber-JS yet, or even with modern JavaScript. (And I'm complicating things with Angular and Protractor.)
This isn't precisely about cucumber-js, but can anyone point me to how to dynamically inject a mock Angular service under the control of the scenario? The articles I've found all seem focused on static DI to wire up an Angular app.
I would like to create reports on Cucumber by using the plugin: multiple-cucumber-html-report and it works just fine.
However, the issue I'm facing is when trying to generate the JSON file, I'm using Cucumber 3.0.1 and I'm trying to generate a JSON format file
this the code I'm using to generate the HTML report:
// Create the HTML report
const report = require('multiple-cucumber-html-reporter');
report.generate({
jsonDir: './features/reports/',
reportPath: './features/reports/'
});
this is the code I'm using to generate the JSON file:
// Create the results JSON file
var jsonFormatter = new Cucumber.JsonFormatter();
jsonFormatter.log = function(report) {
const jsonReport = JSON.parse(report);
// Generate a featurename without spaces, we're gonna use it later
const featureName = jsonReport[0].name.replace(/\s+/g, '_').replace(/\W/g, '').toLowerCase();
// Here I defined a base path to which the jsons are written to
const snapshotPath = path.join(projectRoot, './features/reports');
// Think about a name for the json file. I now added a featurename (each feature
// will output a file) and a timestamp (if you use multiple browsers each browser
// execute each feature file and generate a report)
const filePath = path.join(snapshotPath, `report.${featureName}.${new Date}.json`);
// Create the path if it doesn't exists
fs.ensureDirSync(snapshotPath);
// Save the json file
jsonFile.writeFileSync(filePath, jsonReport, {
spaces: 2
});
};
When running I get this error:
TypeError: Cannot read property 'eventBroadcaster' of undefined at /node_modules/cucumber/lib/formatter/json_formatter.js:55:12
I'm using the following libraries versions:
** ├─┬ cucumber@3.0.1 ** │ ├─┬ cucumber-expressions@4.0.3 ** │ ├── cucumber-tag-expressions@1.0.1
The json formatter requires to be passed in an eventBroadcaster. This is something only cucumber can create. An alternative approach would be to use the json formatter via cucumber-js cli and then parse the json file after cucumber-js has finished executing to rename the file as needed
Actually, that is what I ended doing creating the json file via CLI and I'm about to parse it so it can match the format for the HTML reporter
However, on Cucumber 3.x I'm not sure where to find samples or anything to do that you just said: "The json formatter requires to be passed in an eventBroadcaster." @charlierudolph
Another thing is that the CLI created the JSON file, however, when trying to parse it, it returns an error:
Unexpected end of JSON input
oh I just discovered that I should generate the HTML report on a different JS file rather than the Hook
hello! I'm trying to find out how to get the older reporting syntax from cucumber2 (javascript) back (dots is awesome, but its pretty hard to know when things go haywire)
Also, if there is a recommended approach for running tests in parallel in JS land that would epic!
Hi! In my team we are trying to generate reports with cucumber-html reporter, but they are facing an error and we don't know how to fix it: ```ERROR: a handler errored, process exiting: cucumber/steps/hooks.js:39: suite.features.forEach is not a function
cucumber-html-reporter v2.0.3
wdio-cucumber-framework v1.0.2
which has cucumber v2.3.1``` Have anyone here seen a similar error and can help?
Cucumber 3.0 JS broke my tests so I reverted. What stopped working for me was my screenshot/ browser log methods. I was keying off of scenario.isFailed()
```/*Runs after test Outputs browser logs & Takes screenshot on failure */ After( async function (scenario) { if (scenario.isFailed()) { const world = this; browser.manage().logs().get('browser').then(function(browserLog) { console.log('browser log: ' + require('util').inspect(browserLog)); });
return browser.takeScreenshot().then(function (screenShot) {
world.attach(screenShot, 'image/png');
});}```
anybody know what the cucumber 3.0 equivalent to this code block would be?
@droyster there is an issue on github iirc. Maybe @charlierudolph or @jbpros can help?
no problem found it! https://github.com/cucumber/cucumber-js/issues/937
Latest docs on the matter: https://github.com/cucumber/cucumber-js/blob/v3.0.3/docs/support_files/attachments.md
Hi there. Is there any way to remove the messages in logs that are between Undefined Step Snippets? I would like to copy/paste multiple step defs into my source file. To illustrate the issue, currently this is the output:
1) Scenario: My Scenario - test/specifications/specification-workspace-for-software-teams/maintain-specifications/test.feature:3
Step: Given a precondition - test/specifications/specification-workspace-for-software-teams/maintain-specifications/test.feature:4
Message:
Undefined. Implement with the following snippet:
Given('a precondition', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
2) Scenario: My Scenario - test/specifications/specification-workspace-for-software-teams/maintain-specifications/test.feature:3
Step: And another precondition - test/specifications/specification-workspace-for-software-teams/maintain-specifications/test.feature:5
Message:
Undefined. Implement with the following snippet:
Given('another precondition', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
I would like it to be:
Given('a precondition', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
Given('another precondition', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
Any way to do this?
There is a snippets formatter for this purpose: https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#formats
thanks @charlierudolph - I saw that and tried it but I must have done something wrong. Works now 🙂
cucumber-expressions 4.0.4 is out with some bugfixes: https://github.com/cucumber/cucumber/blob/master/cucumber-expressions/CHANGELOG.md#404---2017-10-05
I started a proof of concept with protractor, angular, and cucumberjs. See if https://github.com/gdinwiddie/AngularCucumber helps at all.
It's quite similar to that: https://github.com/wswebcreation/protractor-cucumber-typescript-boilerplate
@gdinwiddie started a proof ok but do you using this combination in work?
A client is. (This isn't their code, but I did this helping them work out how to do it. I didn't have access to their repository.)
(I got bogged down in the Angular portion after the guy who knew Angular got pulled off for emergency work on another project. Anyone know how to dynamically inject a service using Angular?)
Hi. I'm new to Cucumber(.js) + BDD. Looking at line 32 + 36, there's no callback, and it seems common with other examples. http://cucumber.github.io/cucumber-js/. This is my version and I'm using callbacks https://pastebin.com/Lsk9MVyj. is either method wrong or better or .. ?
*Thread Reply:* @txm "This page is no longer available. It has either expired, been removed by its creator, or removed by one of the Pastebin staff."
*Thread Reply:* @gdinwiddie thanks. I'm not 100% sure what it was, I inherited a few samples, I introduced a nice mix of callbacks and Promises. I've set SELENIUMPROMISEMANAGER=0, removed the callbacks and am returning Promises everywhere (without catch) and am trusting them to do their thing and touch wood making good progress.
hey! Any chance someone knows how I can get the test reports to show up in the cucumber 2 format rather than the cucumber 3 dots?
cucumber-js removed the pretty formatter in 3.0. Any scenario that doesn't pass, appears as pretty printed thought
hi, does anyone know where cucumber. js outputs results? we are trying to integrate into jenkins. Thanks guys
@diavadai by default it outputs results to stdout. See cucumber --help for help about different output formats and how to write results to a file.
Hi, Does anyone know why this doesn't work Given(/^I go to "([^"]**)"$/, function(site) { browser.get(site); }); I just get a timeout error and the site doesn't load in the browser
Is browser.get synchronouns and do you expect it to complete in less than 5 seconds?
should load in less than 5 seconds, but the browser just opens and then closes, don't even try to navigate to the site
There are advantages or disadvantages of using direct connect to web driver over connecting to selenium server or vice versa?
@Yemi try:
Given(/^I go to "([^"]**)"$/, async function(site) {
await browser.get(site);
});
Assuming you're using a promise-based browser like webdriver.io
any one here worked with async/await in Protractor with Cucumber. I am seeing that my Cucumber steps pass without the protractor steps being completed
*Thread Reply:* try adding browser.driver.sleep for 1000ms as first step in every stepdefinition and see if you can actually view some execution happening on the screen
Well I can't because it's from my company. However I'll try to have a similar set up tomorrow so that I can at least demo it
I have been searching this for the last week but haven't been able to get any satisfying answer
due to this I even removed my scenario outlines from the test still they fail
There aren't many examples for async/await with Protractor and Cucumber JS and that doesn't help though.
https://github.com/wswebcreation/protractor-cucumber-typescript-boilerplate https://github.com/igniteram/protractor-cucumber-typescript
well these are basic scenarios which work for basic tests but when trying to scale up multiple tests, these both have issues. However, the second one is the one on which I have based my framework
yeah Ram's framework is a good one and works pretty well but for some reasons my async tests don't wait for the time they should wait for the promise to resolve and they move on to the next step , with the previous step still in progress
*Thread Reply:* i am not using proctractor but i had the same issue. What helped was return and chain the promises together.
Hi! I'm trying to setup cucumber-js with Appium. I want to create CustomWorld with webdriverio driver. Maybe someone has same issue?
Hi everyone, I’m working on getting some front end coverage around a legacy site before we start working on more back end functionality. The issue I’m having is that most actions perform page reloads to process interactions. I’m using the example from https://github.com/igniteram/protractor-cucumber-typescript, but I’m trying to figure out the best way to wait for the page to finish loading (like document.ready) befor checking for my ‘Then’ conditions.
Hello @Chip, besides that url is different, something else changes too? Like page title?
Not too often, most of what I’m trying to get coverage around is something like:
Scenario: Search with results
When I enter "foo" into the keyword field
And I click the search button
Then I expect to see results
The problem is that the ‘Then’ check is firing before my back end has finished searching, generating the new page, and returning it.
I’ve done some stuff with ExpectedConditions looking for text at the bottom of my page - e.g. copyright text, but it feels a bit fragile
Basically yes. I could break it out into 2, but one of which would (almost) always be some sort of wait for the page to finish loading.
hi, does anyone know how i can specify the output location for screenshots when i use word. attach? thanks
When you use the attach passed to the world constructor the contents are available in the JSON and event formatter outputs and do not get output to the filesystem
For me is hard to say but If you will return promises or wait for them(await) it should inform you if certain element was found or not
you put this console.log(element) into driver.findElement() which wasn't returned
Is it ok to use the arrow function as I'm importing the driver from a module? I've read in various places it's a bad idea
arrow function doesn't pass this so you need to be careful, there are probably other restrictions but I think this is main one
Hmm something isn't right, it's timing out even when I have until.elementLocated({css: 'body'});
Is there anything I can use to test the state of the page/connection?
@KariiO I'm getting a timeout even when targetting http://www.google.com with driver.get? Is there anyway to get more information on what's going on?
Given('I am on the right page', async function () {
await driver.get('<http://www.google.com/>');
});
Apologies I thought you are using Protractor. I didn't dive in selenium-webdriver docs so can't say where problem is 😕
but as far I can see most of methods returns Thenable<T> which is like Promise<T> so should work
Ah ah – selenium-webdriver has a promise manager built in and ''aync/await" breaks it
There is also: http://webdriver.io/
Personally I don't like chaining promises, it would be difficult in complex implementations.
Which would make sense if I'm using it for everything else 👍
When a row from a Scenario Outline examples table fails, is there anything in the Cucumber-JS default output that shows which row it failed at. I’m looking at a failing scenario outline and can’t see anything.
Except, of course, the actual assertion that failed.
Can you paste an example of the output? It should print the file and line number that goes to the row.
Thanks @charlierudolph, now that you point it out, I can see that the line number of the failing example row is output.
@charlierudolph is is possible to get the name of the current profile from within your support code?
It would be quite useful for us to be able to check the profile in support code and then configure a different set of adapters in the app - e.g. a fast profile using an in-memory fake database.
At the moment we use a set of environment variables to pass that info in, but it’s messy.
Could you use the --world-parameters option in the fast profile and then handle it in the world constructor?
Hi All,
I recently updated Cucumber in a project that I am working on and part of the hooks functionality broke.
import {defineSupportCode} from 'cucumber';
defineSupportCode(function({Before, After}) {
...
After(async function (scenario) {
if (scenario.isFailed()) {
let data = await driver.takeScreenshot();
...
For the above I am getting the following error:
TypeError: scenario.isFailed is not a function
Any idea how to fix it? I checked in the doc and stackoverflow but couldn't find something helpful.
Many thanks!
*Thread Reply:* Sorry, I got the wrong end of the stick.
The new scenario object has a different structure: I had to change this line to read:
After(function (scenarioResult) {
if (scenarioResult.result.status !== 'passed') {
...
Or equally, you could write:
if (scenarioResult.result.status == 'failed') {
...
I worked this out by using console.log(JSON.stringify(scenarioResult)); - YMMV
See updated examples here for checking if a scenario failed in a hook: https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/attachments.md
@charlierudolph I keep seeing people using import {defineSupportCode} from 'cucumber'. Can we deprecate that method and point people towards the more elegant import { Given, When, Then } from 'cucumber'?
Hi, all! Does anyone have a working example of CucumberJS with Selenium? I find the examples on github in version 3.0 quite complicated.
I'm also seeing this one. It seems that the World object isn't available to the AfterAll hook - which is annoying if you e.g., want to log out at the end of everything...
Ok, I think this is a new bug: AfterAll doesn't seem to have any World defined - is that right?
'use strict';
var {defineSupportCode} = require('cucumber');
defineSupportCode(function ({AfterAll}) {
AfterAll(function () {
this.website.logOut();
});
});
Results in:
Unhandled rejection VError: an AfterAll hook errored, process exiting: features/support/hooks.js:5: Cannot read property 'website' of null
Where this.website.logOut() is defined in the World object, and used everywhere else.
New Bug?
*Thread Reply:* Problem solved: AfterAll runs after all scenarios.
Yep. Cucumber creates a new World instance for every scenario. Which one would you expect to have access to from AfterAll? The last one? That would seem a little arbitrary/odd to me.
Hi everyone, can someone explain in simple terms, why would one want to use Nightwatch.js with Cucumber.js as opposed to just using Cucumber.js?
@barbara.cabral uploaded a file: Pasted image at 2017-12-28, 2:00 PM
my protractor can't find the steps inside the step_definitions files in my project
I'm not familiar with protractor @barbara.cabral - have you tried to ask in their forums?
*Thread Reply:* It was the version of the cucumber... the version that worked fine to me was: "cucumber": "~1.3.2", "protractor": "^5.1.1", "protractor-cucumber-framework": "^3.0.0"
*Thread Reply:* @barbara.cabral did you search the GitHub issues for protractor-cucumber-framework to see if anyone else has the same problem?
Hello experts! 🙂 Does anyone know how to basically achieve AfterStep hooks for recent cucumber-js , 3.2.0 ? based on this link, https://github.com/cucumber/cucumber-js/issues/891, there is something called setDefinitionFunctionWrapper that should be able to accomplish the wanted behaviour, but I do not understand it. Does anyone has any example that can achieve the same? The use case is rather simple. I want to verify that the web application is not throwing any browser console error during each step.
No one? is there no wish from anyone to be able to do the above function?
setDefinitionFunctionWrapper was implemented for turning generator functions into promises. Thus I don't think it has the configuration you need. Please create an issue and we can look into creating such a more useful wrapper as that I believe is something other frameworks would also find useful
So now you should have node_modules/.bin/cucumber.js, which you can point IDEA to
IDEA won't know that you uninstalled it. You need to tell it where your new installation is.
yep, I figured it out. Had to edit default config settings for cucumber.java
Greetings! Updating cucumber from v2.3.0 to 3.2.1 using TypeScript with Cucumber Js broke the console report 😞 The bad thing is that there is nothing related to this on web... at least I couldn't find it
@Oleg shared a file: image.png and commented: don't pay attetion to chrome v63 errors
*Thread Reply:* I'm trying to solve problems with this new version. But without sucess...
Hey guys, can anyone point me in the direction for documentation on how to use Example: in cucumber-js?
*Thread Reply:* https://www.sitepoint.com/bdd-javascript-cucumber-gherkin/ This walkthrough includes the examples syntax
My tests seem to timeout quite often, is there anything I can do about that?
may want to throw in some waits around the likely culprits.
i.e., browser.waitForExist(myElement, 3000);
Hi Guys, did anyone work with cucumberJs + protractor for an application which is mix of angular and non angular? If so, I need some help with how to integrate transition between angular pages and non with protractor
Hi, We used cucumber for tests along with Angular 1.x , I've recently moved to a new role, and here we are using React. Is there anything special that needs to be done to set up e2e tests with React and Cucumber?
*Thread Reply:* You’ll probably want to swap to something react-specific or at least not-protractor. Protractor can be used with non-angular frameworks, but I found it a bit clunky compared to just using something framework-agnostic
*Thread Reply:* I read somewhere that provided you switched off the synchronization, it was ok to use Protractor, and also if we put in the Expected Conditions in the test to "work out" when to start.
*Thread Reply:* I don't know of any react specific for this. What did you use in the end?
*Thread Reply:* Webdriverio - works across frameworks + mobile and electron apps
*Thread Reply:* Automation: the game of “How ~lazy~ efficient can I possibly be?”
Hi, I'm using cucumberjs with protractor. When I tried to add a hook file to my test, I received this error message:
@barbara.cabral uploaded a file: Pasted image at 2018-02-14, 5:43 PM
anyone did already see this error? I was finding in the internet and it could be the version of node installed. What do you think about it?
hey, running with cucumber version 2.0.0-rc.9 and when i go to view the results in the cucumber jvm reports jenkins plugin the scenarios are all zero's. Been doing some looking around and the problem appears to be that the getCountSummary function in cucumber\distcucumber.js:57227 is looking specifically for `type:'scenario'. However when i look in the result json it is missing. Does anyone know is this still an issue with higher up versions? or is there a fix?
have tried a few version upgrades in the mean time and now using version 2.3.1 which has the getCountSummary function in cucumber\dist\cucumber.js:54139 which counts the`type:'scenario', though this still doesn't work with the jenkins report
current output from json results file for scenario
"elements": [
{
"keyword": "Scenario",
"line": 15,
"name": "Header exists",
----- should have a type field here but do not ----
"type": "scenario",
--------------------------------------------------
"tags": [
{
"line": 1,
"name": "@x-browser"
}
]
think i have found the version i need https://github.com/cucumber/cucumber-js/pull/893
@charlierudolph I've created my own image based in the last versions of the frameworks (versions working together of course). Thanks for the help! 🙂
Hello guys, with upgrade to cucumber 3.2 we are unable to take screenshot after step failure when using ignoreUncaughtExceptions: false.
Anyone has any idea how can we implement screenshot functionality on step failure while using settings ignoreUncaughtExceptions: false. ?
CucumberJs doesn’t have the option ignoreUncaughtExceptions: false. What tool are you passing that into?
Hi, I hope it is okay to post this help request here on Slack, my apologies otherwise.
I have been trying to test IE 11 using Protractor and the Cucumber Test Framework (via Cucumber and protractor-cucumber-framework) on a Windows 10 laptop. So far this hasn't worked despite numerous attempts. Yet when I switch the test framework over to Jasmine it all starts working. We want to use Cucumber for our system test automation program. Full details; including copies of the example project code files; can be seen at: https://stackoverflow.com/questions/49261946/protractor-v5-3-0-protractor-cucumber-framework-v4-2-0-not-working-with-ie11-o
Either way many thanks for looking...
cucumber-js has issues with IE 11. See https://github.com/cucumber/cucumber-js/issues/1011. Does it work in other browsers?
@charlierudolph Hi there, I've just double-checked it by running my trial project in Chrome v65.0.3325.181 and the tests run as expected. I've followed the link inside Issue#1011 and I get the expected error when using IE 11 - that is "'Cucumber' is undefined". I didn't see any hint of when this issue is going to be fixed in the issue.
1) Is there any way to know when this will be fixed? 2) Do you happen to know if this can be fixed by downgrading to an older version? In my case I bet that could involve "Protractor", "CucumberJS", "Protractor-Cucumber-Framework" to compatible older versions and I don't how you would tell which those would be at this point (new to using this particular technology stack).
Thanks for the response, at least I know at last that its not a IE configuration issue, corporate security lock down problem, etc. on my test system.
Hi all! Can you help me? How I can run **.steps.js in es6 mode? I have that error:
SyntaxError: Unexpected token import
I found my mistake, thanks!
Hi folks, I'm trying to set up cucumber.js to work with selenium webdriver. I was thinking of building my "driver" in the BeforeAll hook, but for some reason, the "this" in the BeforeAll hook is the Node global "this", and not the Cucumber World. So what I ended up doing was initializing the driver in my CustomWorld constructor. Is this the best practice? Uploading my steps.js file below.
In addition, if all my Scenarios for a given feature occur at the same page url, where do I call drive.get(url), if not in BeforeAll? Do I call it in the first scenario, and have the Given state for the first scenario carry over into subsequent scenarios? Thanks!
See here for docs on BeforeAll / AfterAll and why this is not a world instance: https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/hooks.md#beforeall--afterall. If you want to share something like a browser between all scenarios, you need to handle that yourself. Cucumber does not have specific support for that because it wants to encourage users to keep scenarios independent so they cannot effect each other. If all scenarios in a feature have some shared precondition use a Background block in your gherkin.
Thanks @charlierudolph, it seems like a Background block is the way to go!
hi all. brain hurts. craving 🥒 . need help. I posted my questions in #help before I knew of this channel. If someone could kindly take a peek and see if they can assist me, I would greatly appreciate it.
well, seems my stumbling block has been not knowing about helper functions. at least in part.
I may be stumbling down the wrong rabbit hole bc I’m getting nowhere. I want to do two things: >1. figure out how to use helper methods for my steps, and >2. mock up a user login to pass into a step definition for creating an account. I can’t seem to get either correct. I created a gist in case someone wants to investigate. Help is always appreciated. https://gist.github.com/mjstelly/e4d6dee11b4ea9205ca512fcaa8e8c49
That could be it. Still learning how to use the Revealing JS pattern
From what I'm reading, the Revealing pattern does not need to be exported. It is a self-invoking function, so importing it into the calling module "reveals" the public API identified in the object returned from the called module. That's how I understand it. If someone has a better understanding, please advise.
And my thought is that I should be able to destructure it like the react module. But I'm new to the ES6/ES7 way of doing things.
I was wrong. I do need to export it. Got my hands on some production examples. Still can't get it to work. I've updated the gist with what my new code. See if anyone can help with that. https://gist.github.com/mjstelly/e4d6dee11b4ea9205ca512fcaa8e8c49
yarn run v1.5.1 $ cucumber-js F-
Failures:
1) Scenario: Create a new user # features/accountCreate.feature:5 ✖️ When I create a new member # features/stepdefinitions/accountCreate.steps.js:5 TypeError: setCreds is not a function at World.<anonymous> (/Users/michaelstelly/Documents/projects/mobilegtm/features/step_definitions/accou ntCreate.steps.js:7:3)
1 scenario (1 failed) 2 steps (1 failed, 1 skipped) 0m00.001s
It's weird. If I keep the function within my step module, the tests pass.
can someone provide an example of using the Revealing Module pattern for ES7? I can't get it to work. My helpers.js snippet is an example of what I've tried so far.
I think this might be the answer. Gonna give it a go. https://stackoverflow.com/a/44373830/226118
Hmm, that didn't end well. I have function login(); export { login }; in my helper. I then import (or so I think) into my step file as const { login } = require('../support/helpers'); When I run cucumber, I get the error
$ cucumber-js ../features/support/helpers.js:12 export { login }; ^^^^^^ SyntaxError: Unexpected token export
Ahh, someone suggested that cucumber may not yet support ES6/7 import/export. Is this the case?
Ok. Found the solutions. Needed to install babel-register and add to the cucumber.js file,
module.exports = { default: --require-module babel-register --format-options '{"snippetInterface": "synchronous"}',};
import / export are not currently supported by node and thus for cucumber to support them, it would need to transpile the support code. We leave it to the user to define what transpilers to use. https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#transpilers
how do i implement Background? In my feature file, I have Background: Given I am a registered user. When I run cucumber, I get
1) Scenario: Log into the app # features/login.feature:8
✖ Given I am a registered user
Multiple step definitions match:
I am a registered user - features/step_definitions/loginUser.steps.js:14
I am a registered user - features/step_definitions/loginUser.steps.js:41
I am a registered user - features/step_definitions/loginUser.steps.js:63
I am a registered user - features/step_definitions/loginUser.steps.js:90
I am a registered user - features/step_definitions/loginUser.steps.js:117
And any associated steps report as Ambiguous
5 scenarios (5 ambiguous)
23 steps (9 ambiguous, 14 skipped)
0m00.000s
your background step looks good, the issue is that you have defined multiple step definitions that match "I am a registered user"
you only want to define a step one time, but you can use it in multiple scenarios/backgrounds however many times
No, a scenario could be written entirely with And it's just a helper to make it read more naturally
What I meant about having defined the step multiple this is this, you have the same step defined inside loginUser.steps.js on line 14, 41, 63, 90, and 117
you only need to have Given('I am a registered user', function() {
// Write code here that turns the phrase above into concrete actions
return 'pending';
}); written once in the steps file
some of your other steps are defined multiple times as well, such as When('I press Remember Me', function() {
oh, ok. that was the generated template. i see now. thanks. this is all new to me. so i'll probably make more of these mistakes. appreciate it.
Yea, for some reason the JS version of cucumber will give the same sample snippet multiple times in a run if it is used multiple times. Other languages I've used Cucumber with condense it down to one set
Maybe I don't understand how steps are supposed to work. I have different scenarios that lead to the same place. How do I represent them? For example, submitting email/pw or connect with FB both lead to display the home page. So both contain Then('displays the home page', function(){ blah });. Cucumber reports it as ambiguous. But if I remove one of them and then, later, someone else reads the script, they might wonder why that step is missing. Does that make sense?
same goes for a toggle button. Both steps would include When('I press Remember Me', function() { blah });
What if I have same Background in different Feature steps? cucumber-js will show warnings about it. What is the best practice with this situation?
Why if I run one feature cucumber-js features/sign-up/sign-up.feature are all Before hooks executing?
1) Scenario: Tenant admin is registered # features/sign-up/sign-up.feature:10
✔ Before # features/sign-in/sign-in.steps.js:4
✔ Before # features/sign-up/sign-up.steps.js:4
<- not an expert, but from what I read, background is limited to the scope of that feature. If you want behavior for multiple features, it needs to be a hook, or maybe a helper method.
There is not a lot of info out there on setting up cucumberjs. Anyone have a good resource and or info?
@DavidTran there's not much to set up, really. Are you having a specific problem?
install with npm or yarn. then in my package.json, I add "scripts": {
"cucumber": "cucumber-js",
} and in the project root, I run yarn cucumber
May have to start from scratch. Been looking at some of the boilerplate implementations and running into issues. Most likely will use cucumber-js and webdriverio, since I have React and Angular apps.
so, uninstall cucumber, and reinstall. yarn yarn add cucumber --dev for npm, it's npm -i --savedev cucumber, I think. I don't use npm anymore.
If cucumber is a documentation tool and NOT a testing tool, then whoever is maintaining the cucumber-js github repo is confused. The first sentence in the README states
>Cucumber is a tool for running automated tests written in plain language.
Perhaps the author of that wasn't confused but the definition of what Cucumber is has been refined since that was originally written? ¯_(ツ)_/¯
@charlierudolph committed that line April 14, 2016 - https://github.com/cucumber/cucumber-js/commit/cd68105df2fa3853362b6000c9dad7511d3b7aa4
The commit linked is authored by Julien. I’m happy to update it. Any proposed revisions?
I’m still trying to wrap my head around what appears to be a confusion by the general populace of what exactly cucumber is and is not. Is it a collaboration tool, or an acceptance test-driven development tool, or an automated test runner, or something else? Even Wikipedia promulgates the confusion >>>Cucumber is a software tool used by computer programmers for testing other software.[7] It runs automated acceptance tests written in a behavior-driven development (BDD) style.
Sometimes - especially when communicating with folks outside of development - it helps when I also explain what Cucumber isn’t. For example: It’s not an assertion framework. It’s not a browser driver.
Ok - try reframing it. What question - specifically - are you trying to answer? Beyond “What is Cucumber?” Is it “What business value does Cucumber deliver?” or “What purpose does Cucumber serve in an automation stack?” Or “How can Cucumber help us produce the right features at the right time?” etc.
No, those business questions are readily answered, which is a plus. I’m trying to understand how and where do I put my tests. Although I’m not expert at writing feature files, they’re the easier part.
and since i’ve never written tests before, I’m trying to learn how to put my Jest tests into my steps files.
Technically speaking, you’d probably want to abstract out the Jest bits from the step defs
*Thread Reply:* so, are you saying put assertions and tests in a helper file?
*Thread Reply:* yup. a good example of this is the cucumber-wdio boilerplate (I know you’re using jest, but seeing how they’ve constructed the helpers may be useful for you) https://github.com/webdriverio/cucumber-boilerplate Note that this looks like its builds are failing (I suspect since wdio-cucumber-framework was only recently updated to 2.1), so just use it as POC for grokking the concept for now 🙂
*Thread Reply:* and look at how they’re implemented in src/steps -> src/features
*Thread Reply:* After a quick look at the readme, I again bump into point of confusion. It’s steps have very implementation-specific definitions like Given the checkbox "([^"]**)?" is( not)** checked.... I’ve been informed that this is an anti-pattern and should be avoided in these files. What is your experience with this?
*Thread Reply:* I think it really depends on the specific thing you’re testing. If you have a UI toggle and you need to test what happens if toggled on vs. toggled off, it’s not a bad way to go - because then it’s not so much implementation specific as expressing specific conditions that need to be met prior to performing an action + expected outcome
*Thread Reply:* I also think it depends on how many different elements you have that would have completely different selectors but very similar descriptions (like you have 75 different checkboxes that all have totally different selectors and no common classes or anything)
*Thread Reply:* thanks again for the input. as long as you're willing to help, i'll be pinging you for it. 😆 At least until the fog clears. I stare at my step-def files and go "now what?" 🤷
and that would make sense. so you can see why i get confused. trying to learn cucumber from one side, and Jest on the other, and assertions in the middle, it’s a big jumbled mess right now.
I need some help thinking through this scenario:Scenario: Select health goals
Given Sara wants to select her health goals
When zero or more health goals are selected
Then the health goals are added to her account information
The UI will display a 3x2 grid of buttons that become highlighted when selected. When the user presses Next, the selected items will be passed to a data array and added to the user mobx store. My question is: how do I represent the action of selecting these goal buttons in my step definition file?
@Michael Stelly What exactly is the concrete action/setup behind Given Sara wants to select her health goals ?
From reading that, it looks like there's the option to not select any goals?
@Gem the action is to select buttons that represent certain health goals that will be added to the user profile. But it’s not mandatory to select them at this time. User can edit their profile later.
Are you equating her wanting to select health goals as a way to ensure the system is on the correct page?
yes, this is where I get conflicted. one person says “don’t discuss implementation in steps”, another says “be more concrete”? ¯_(ツ)_/¯
Ok, waiting for you to espouse the “frogs on a log” parable…:waiting:
This is the new user signup process. first they enter their info, then select their goals
@Michael Stelly What're your thoughts on this?
Feature: Health goals can be added to an account's information during sign-up.
Rule: Health goals selected must get added to an account's information
Rule: Health goals are not required to be selected
Scenario: Health goals get selected
Given Sara is on the health goal selection signup step
When Sara selects two health goals
Then the selected health goals should be found in her account information
Scenario: No health goals get selected
Given Sara is on the health goal selection signup step
When Sara selects no health goals are selected
Then no health goals should be found in her account information
It's still got some room to be more concrete, but that's what I've whipped up
Just trying to keep example mapping in mind and illustrate that's what I came up with.
Underneath feature titles you can add whatever data you'd like to help explain things. Commonly you'll see the 'as a xyz, I want to foo, so that bar' entry in that area
Console error:Error: Parse error in 'features/addHealthGoals.feature': (3:3): expected: #EOF, #
Comment, #BackgroundLine, #TagLine, #ScenarioLine, #ScenarioOutlineLine, #Empty,
got 'Rule: Health goals selected must get added to an account's information'
Anyone here using Jest? I’m trying to learn how to incorporate jest tests with my steps definition files.
*Thread Reply:* Yes - just starting out trying to get Jest to work with cucumber - using Jest-cucumber. Working good so far
*Thread Reply:* https://www.npmjs.com/package/jest-cucumber
*Thread Reply:* that's what i'm using as well. Learning multiple tools at once is quite harrowing. Like swimming through quicksand.
*Thread Reply:* Oh, this is gonna be rough. I'm getting syntax errors that have totally unhelpful message. 🤦♂️
Hey everyone
Been looking to Upgrade cucumber from 2.x to 4.x. We use Typescript for our project
Are there any examples for getting Feature names that I can refer.. I am unable to understand how to use the interface events.FeaturesPayload that returns me the getFeatures() that should contain the info i required. Any help would be great. Thanks
World is unique between features or save its state?
I want save some data in this.data in one Feature and get them in another Feature.
@dmshamonov Read about world here https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/world.md
Can anyone help me to know how to execute multiple feature files using tags in a particular sequence in cucumber js
@sunil s from my understanding, having sequential dependencies is not a good idea (anti-pattern). @Gem may be able to clarify further.
If someone is learned about jest-cucumber, I could use help deciphering this arcane error message
```$ jest
FAIL features/accountCreate.feature
● Test suite failed to run
/Users/michaelstelly/Documents/projects/mobile_gtm/features/accountCreate.feature:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){Feature: Create a new member account
^
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:316
:17)``` What is unexpected about the feature: >>>Feature: Create a new member account As a nonmember Sara wants to create a user account
*Thread Reply:* I think that error comes from trying to parse a .feature file as a .js file. Can you check your configuration for what files are being loaded as if they were javascript?
*Thread Reply:* My testMatch mirrors the recommended config "testMatch": ["****/**.steps.js", "****/**.feature"]
*Thread Reply:* I don’t know the jest config. I would look for support on the jest side (wherever the cucumber plugin lives)
@Michael Stelly You got it WRT to dependencies. @sunil s Every scenario you write should be atomic from one another (aka, able to be run on their own)
My message had no takers 😞
*Thread Reply:* the internal hooks changed a lot in 3.0. What is your use case for needing the feature names?
*Thread Reply:* Thanks for the response Charlie, I run Ui tests through the framework and use browserstack as my remote server.
The framework previously would allow me to get feature names at the start so that when I run tests in parallel using node processes , I could easily mark each feature by the Browser it is run on and post to Browserstack.
That way I name my browserstack session runs which are per feature in my case. Now I know you’d say its not ideal, but it was a conscious decision to run each feature file on a single selenium session and update app state per scenario so that the scenarios were still independent of each other.
*Thread Reply:* That’s not possible anymore. The closest thing you can get is the parameter passed to a before hook. See the api reference doc for more info
I read this but not found answer for my question. I decided what World saves its state only in one Feature context.
@dmshamonov state is generated separately for each feature. you might be able to use a state manager like redux or mobx to store data, then call it in each set of tests.
*Thread Reply:* Not sure. I’m throwing out ideas here. But if you want to set the environment for each feature, you’ll have to generate some kind of state.
*Thread Reply:* I’ll defer to others that have more experience with this. Also, try the regular #help channel. That may get the answer you need.
*Thread Reply:* @dmshamonov Have you tried using hooks w/ tags to solve your problem? https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/hooks.md
*Thread Reply:* You can do a 'Before' to set the state you desire before any scenarios are ran from within a tagged feature. Otherwise I believe the world object is replaced with each scenario (because no scenario should rely on a previous scenario)
*Thread Reply:* @Ed Snodgrass Ok... In hook "Before" or "Background" I init some data for "Scenarios". Example I create some entity there and save IDs in "World". And I need to delete those entity in end. But in "After" hook "World" isn't available...
*Thread Reply:* @dmshamonov, When I set a value on world, i can print out its contents in the after hook.
//steps file
const { Given, After } = require('cucumber');
After({ tags: '@LogWorldAfterScenario' }, function() {
console.log(this.value);
});
Given(/^I have set a value on the world$/, function() {
this.value = 'Hello World';
});
#feature file
@LogWorldAfterScenario
Feature: After Hook should have the world object
Scenario: Test After Hook
Given I have set a value on the world
*Thread Reply:* if the values are set on the world aren't they being cleaned up after each scenario runs?
howdy all! i am trying to run Cucumber tests in parallel on a Selenium Grid, but i’m getting the following error:
undefined:1
SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at Master.parseSlaveLine (/Users/scottthompson/WebstormProjects/mx-vtx-ui-enterprise/nodemodules/cucumber/lib/runtime/parallel/master.js:70:24) at Interface.<anonymous> (/Users/scottthompson/WebstormProjects/mx-vtx-ui-enterprise/nodemodules/cucumber/lib/runtime/parallel/master.js:102:15) at emitOne (events.js:115:13) at Interface.emit (events.js:210:7) at Interface.onLine (readline.js:278:10) at Interface.normalWrite (readline.js:420:12) at Socket.ondata (readline.js:138:10) at emitOne (events.js:115:13) at Socket.emit (events.js:210:7) at addChunk (streamreadable.js:252:12) at readableAddChunk (streamreadable.js:239:11) at Socket.Readable.push (streamreadable.js:197:10) at Pipe.onread (net.js:589:20) Unable to parse cucumberjs output into json: ‘test/automation/reports/cucumber-json-report.json’ SyntaxError: test/automation/reports/cucumber-json-report.json: Unexpected end of JSON input at JSON.parse (<anonymous>) at Object.readFileSync (/Users/scottthompson/WebstormProjects/mx-vtx-ui-enterprise/nodemodules/cucumber-html-reporter/nodemodules/jsonfile/index.js:69:17) at isValidJsonFile (/Users/scottthompson/WebstormProjects/mx-vtx-ui-enterprise/nodemodules/cucumber-html-reporter/lib/reporter.js:416:48) at Object.generate (/Users/scottthompson/WebstormProjects/mx-vtx-ui-enterprise/nodemodules/cucumber-html-reporter/lib/reporter.js:438:9) at Object.generateReport [as generate] (/Users/scottthompson/WebstormProjects/mx-vtx-ui-enterprise/nodemodules/cucumber-html-reporter/index.js:30:21) at Object.<anonymous> (/Users/scottthompson/WebstormProjects/mx-vtx-ui-enterprise/nodemodules/@pps/testing/htmlReporter.js:11:10) at Module.compile (module.js:569:30) at Object.Module.extensions..js (module.js:580:10) at Module.load (module.js:503:32) at tryModuleLoad (module.js:466:12)
anyone have experience using cucumber with jest? if so, need some config and basic usage help. 👍
fyi, figured out my issue — console.log()!! https://github.com/cucumber/cucumber-js/blob/58caad38be582490ebb1ad4c8e9fe01b2732ace4/docs/cli.md#parallel-experimental
Note: Printing to stdout (using console.log or other means) will cause an error, because the slave processes communicate with the master process over stdout. Instead print to stderr (using console.error or other means).
fyi, what I've done for log cleanup is define a boolean doLog flag, then add doLog && console.log(); in my code. when I want to switch it off, just set doLog = false; Problem solved.
saves a lot of grief over random log statements throughout the code base.
running --parallel against a Selenium Grid, i am getting Cannot read property ‘attachments’ of undefined in my after hook that generates a screenshot on Status.FAILED
*Thread Reply:* thanks for responding, @charlierudolph. here’s a snippet of that stack trace:
/Users/scottthompson/WebstormProjects/mx-vtx-ui-enterprise/nodemodules/cucumber/lib/formatter/helpers/eventdata_collector.js:103 if (!step.attachments) { ^
TypeError: Cannot read property ‘attachments’ of undefined at EventDataCollector.storeTestStepAttachment (/Users/scottthompson/WebstormProjects/mx-vtx-ui-enterprise/nodemodules/cucumber/lib/formatter/helpers/eventdata_collector.js:103:16) at emitOne (events.js:115:13) at EventEmitter.emit (events.js:210:7)
*Thread Reply:* Looking at the code, I’m guessing that could happen if you attach something (visa https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/attachments.md) after the step/hook is complete. Can you share the code that attaches something?
*Thread Reply:* After(function (scenario) {
const world = this;
if (scenario.result.status === Status.FAILED) {
if (config.env !== 'dev') scenario.result.exception.stack = null;
// eslint-disable-next-line no-undef
driver.takeScreenshot().then(screenshot => {
world.attach(screenshot, 'image/png');
if (config.env !== 'dev') driver.quit();
});
}
driver.quit();
});
*Thread Reply:* Hmm okay. Can you refactor it so the hook so it returns a promise? Its important that cucumber knows the hook is still running. Currently cucumber would move on before the hook finishes running. I can make the cucumber code a bit more defensive so it gives a nicer error message when this happens in the future
*Thread Reply:* okaaay… i get what your saying about timing out and hookage, but…
*Thread Reply:* The cucumber code keeps in internal stepIndex to know what step to attach to when world.attach is called. Since this call happens after the hook finishes, cucumber has incremented the stepIndex to a non-existent step
*Thread Reply:* i see then too why you mentioned updating error messaging also — to be more specific about WHEN that dies
*Thread Reply:* https://github.com/cucumber/cucumber-js/pull/1081
is there a pure javascript equivalent to the cucumberJS method rowsHash()? I'm using jest-cucumber. I'm trying to pass data table row to my mobx store. With cucumber, I could do this
when('Sara provides account information:', userInfo => {
const newMember = userInfo.rowsHash(); and I would have a nice JSON object to work with. I can't do that now, so I need to do something equivalent to that.
*Thread Reply:* I’m confused by your question. Is there a javascript equivalent to the cucumberJS method: they would be one and the same.
*Thread Reply:* yea, i'm pretty fried right now. sorry. I meant a pure javascript equivalent. rowsHash() is part of the cucumber-js API. jest-cucumber apparently doesn't support it. I want to take the Feature data table and transform it to a JSON object. Does that help explain?
*Thread Reply:* I do not know jest cucumber. I’d try to ask that question on the jest-cucumber support channels
Just having a bit of trouble understanding how the Definition Function Wrapper is intended to be invoked: https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/step_definitions.md#definition-function-wrapper
any thoughts on how to transform a feature data table into a JSON object without using rowsHash() or jest-cucumber? I created a gist that I hope sheds light on what I'm trying to achieve. When I execute jest the user model gets populated incorrectly. I surmise that it's not the model's function updateUser because when I transformed userInfo through CucumberJS rowsHash() into a local object, updateUser worked as intended. https://gist.github.com/mjstelly/33eb652d7b454ebc7cc0d78b4c92275d
I logged the forEach() output. The input is garbage (GIGO). I think that's why I need to transform the data table first before passing it to forEach Here's what is processed:
```console.log features/stepdefinitions/accountCreate.steps.js:45
row: { firstName: 'lastName', Sara: 'Lee' }
console.log features/stepdefinitions/accountCreate.steps.js:45
row: { firstName: 'email', Sara: 'sara@example.com' }
console.log features/step_definitions/accountCreate.steps.js:45
row: { firstName: 'phoneNumber', Sara: '2125551212' }
console.log features/step_definitions/accountCreate.steps.js:45
row: { firstName: 'gender', Sara: 'F' }
console.log features/step_definitions/accountCreate.steps.js:45
row: { firstName: 'password', Sara: 'slpw' }
console.log features/step_definitions/accountCreate.steps.js:45
row: { firstName: 'confirmPassword', Sara: 'slpw' }```
Ok, because jest-cucumber doesn't support rowsHash(), I had to do a hack on the data table. Not my preferred method, but it'll have to do for now. 😦
| key | value |
| firstName | Sara |
| lastName | Lee |
| email | <a href="mailto:sara@example.com">sara@example.com</a> |
| phoneNumber | 2125551212 |
| gender | F |
| password | slpw |
| confirmPassword | slpw |
then I changed the call to
const user = {};
userInfo.forEach(({ key, value }) => (user[key] = value));
userStore.updateUser(user);
});
Yes @Aslak Hellesøy "how the Definition Function Wrapper is intended to be invoked"? In the example, what calls setDefinitionFunctionWrapper and who/what supplies the callback? What's it's purpose for existence? From that example it's not obvious what it does, other than the very obvious (wrap a function), which anyone could do with a very small piece of code. Do I need to dive into the implementation to have a look?
@binarymist its very minimal. It was built to deal with turning generators into async/await (before that was as standard as it is now). A user calls setDefinitionFunctionWrapper
It's reminding me of a post I made over eight years ago: https://blog.binarymist.net/2009/12/24/keeping-encapsulation-on-ones-mind/
If I'm understanding correctly, that it's no longer used, would it make sense to remove?
I believe it is used for other instances, such as wdio-cucumber-framework as a way to run something after a step (and have step level retry) I think that will be better suited with after step hooks (another issue). Once we have those, I want to deprecate it asking people to switch to them and create an issue if there use case is not covered
Don't we have AfterStep hooks now: https://github.com/cucumber/cucumber/wiki/Hooks#tagged-hooks ?
According to that doco, the After is for after scenario, is that incorrect?
my mistake. I didn’t follow the link and was assuming you were linking to the cucumber-js docs. Those general cucumber docs are for ruby and are outdated
It's a bit confusing as the before and after hooks work on different points in the main cucumber as opposed to the js cucumber.
The main page of the wiki linked to other docs (which I believe are slso outdated)
It's been about 6 years since I've used cucumber, just getting back up to speed.
Nevermind, the link on the main page of the wiki links to up to date docs
Each language has their own set of docs but there also a global docs that is trying to house everything that is shared
Looks like the quality of the js docs are better than the global docs currently. Thanks for the clarification.
Thanks for the feedback @binarymist and sorry you were confused. The team in the #docs channel would love to hear from you if you have more feedback about the docs, we’re actively working on consolidating them at the moment from what historically had become a bit of a mess!
Oh, cool, didn't realise there was a #docs, thanks. Not so much of a problem when the slack is responsive 🙂 Cheers maintainers, keep up the great work.
curious if anyone had any comments on https://cucumberbdd.slack.com/archives/C6QJ6N695/p1524678639000169
Wonder if anyone else is also experiencing a 404 not found error upon clicking on Cucumber tag expression here https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#tags
has the link been removed from the official docs and the CucumberJs docs havent been updated?
*Thread Reply:* Looks, like it moved to https://docs.cucumber.io/cucumber/api/#tag-expressions. Docs have been updated. Thanks for pointing this out!
I'm guessing for And steps, the intention is to just use a Given, When or Then in the step definitions?
*Thread Reply:* Yes. You can use Given When Then to define the step that uses And in your gherkin doc
This https://github.com/cucumber/cucumber-js/tree/master/features is great doco @charlierudolph. Doesn't look like it's linked to from the main README, but maybe it should be
I have run into a very weird issue :
I have been trying to upgrade cucumber from 2.3.1 to latest that’s 4.2.1
I have made changes to my code and everything has worked fine on my local.
But on CI server (TeamCity), the cucumber node module is missing the bin folder that carries the binary, which is why my tests are not able to run coz the folder is non existing. Where should I start to debug this? I am frnakly unable to think
Is there still a place where one would run the cucumber cli with multiple --tags <tag_expression_here>, or is it all done with a single --tags <tag_expression_here>?
*Thread Reply:* Yes. Didnt work So i installed 3.x and it would packaged the bin folder properly. Only difference between 3.x and 4.x in terms of bin folder is the change in name of the cucumber-js binary and addition of the run_slave binary in 4.x
I'm also wondering if there is a way with the CLI to have it list the feature files that are going to run, based on the tags, etc one has passed as the argv property of the object passed to new cucumber.Cli
https://github.com/cucumber/cucumber-js/blob/master/src/cli/helpers.js#L20 looks kind of interesting
--dry-run just shows the scenarios and steps as though they had passed (two lines of output, rather than the actual contents of the feature file). Is there an obvious way to extract the contents of what will be run as features?
Just wondering if it's easiest/best to hand role something for myself based on what's already in the CLI or actually extend the CLI?
Seems like extending the CLI would make the most sense, but I'm not sure if the maintainers want it extended?
@binarymist we’re considering basing all cucumber implementations on https://github.com/cucumber/cucumber-pickle-runner so any changes should probably go there.
The name is misleading - it doesn’t run anything. It loads scenarios and tells a front-end (in e.g. Java/Ruby/Js) what to run.
What would be the best practise for adding metadata in cucumber (js, cucumber 4) json report? e.g. to use with https://github.com/wswebcreation/multiple-cucumber-html-reporter
Writing my custom formatter? Anyone an example of extending the jsonformatter? (edited)
*Thread Reply:* I use cucumber-html-reporter module and feed the data to it using the inbuilt json outputer.
*Thread Reply:* @arjunjh10 Yeah, somewhat that plugin is almost similar.
I've different metadata for different features - multiple-cucumber-html-reporter supports metadata to be read from the json(s).
My problem is how to get it in there?? 🙂
*Thread Reply:* @len Ok I’ll tell you the way I get the data through Json in case of my framework My Cucumber.js file
const targetResultJson = `./testoutput/<Filename>.json`;
const commonOptions = `--format json:${targetResultJson} --format summary --require-module ts-node/register --require ui/features/****/**.ts --fail-fast`;
my cucumber-runner.ts file
import ** as reporter from 'cucumber-html-reporter';
const outputDir = `./testoutput/${profileName}`;
process.on('exit', () => {
const options = {
brandTitle: 'Test Report',
theme: 'hierarchy',
jsonDir: outputDir,
output: `${outputDir}/${profileName}test-report.html`,
reportSuiteAsScenarsios: true,
launchReport: false,
storeScreenShots: true
};
// This generates HTML report.
reporter.generate(options);
});
Hope it helps
*Thread Reply:* ooh, nice. thanks @arjunjh10 , I'll try that process.on('exit' out soon.
(getting myself into config-hell if I need to add my metadata in a separate process)
@Aslak Hellesøy that readme begs the question: what is a "pickle"?
A pickle is a data structure that identifies a scenario for Cucumber to run.
Regarding my original problem. I forgot to mention, that we package the test project using nuget and upload it to TeamCity. On version 2.3.1 the bin folder was also packaged along with other Cucumber contents. It only seems to be excluding the bin folder from Cucumber 4.2.1. Also, I made no changes to my nuspec package creator file
When is cucumber-pickle-runner going to be a dependency of the cucumber CLI, obviously it's not yet @Aslak Hellesøy?
So it sounds like the answer is: That there isn't currently a way to do this in the CLI, and if we want to implement something in Cucumber (so that the community benefits), then learn Go if we don't already know it, and start hacking on the cucumber-pickle-runner which isn't yet used by the CLI anyway? Alternatively just write some code to read the files ourselves and parse looking for the tags we want?
I reinstalled cucumber but this time chose version 3.2.1 - packaged it using nuget - and my module did contain the bin folder with binary.
So the only thing different between the bin folder on 3.x and 4.x is the run_slave file thats a new addition to 4.x
I am not sure if there is anything wrong with it or not, but this definitely makes me suspicious. Thoughts anyone?
I got a little more experimental -
I changed run_slave file name to run_slave.js and ran packaging again -
This time it created the bin folder
Does this sound like an issue worth fixing?
Not sure why the run_slave doesn't have a .js extension, maybe find out where/when it was removed? Just seeing it myself
as far as I can tell its only included in the codebase in Jan this year.. and has no significant history
Looks like the extensions were not used for both the binaries in the Bin folder for 4.x versions
https://github.com/cucumber/cucumber-js/tree/3.x/bin
Hey, CucumberJs users, regarding my problem with the binary extensions.. should I raise an issue?
@arjunjh10 please do - after you’ve checked the CHANGELOG for any clues about it
We have some scenarios that require expensive and long running setup, which is too slow to run each time.
So we have created a snapshotting mechanism, so you can run the setup once, and reload it subsequently.
No you can’t @Jon. Expensive and long-running setup is something teams need to address in order to keep test time short.
It can be expressed quite succinctly as a scenario, and it something we do want to test in of itself
But we also need to snapshot the state of the system and then re-use that as the basis for other scenarios that test post-build functionality
It sounds like your scenario is verifying at least 2 different things: a) The machine learning algorithm b) Being able to process/use the built predictive model
Is the built model simple enough that you could build it without the machine learning algorithm?
Given the predictive model is:
| a table describing essential parts of the model |
When I ask for ....
Then the result should be ....
With this approach, your Given step would build the same kind of model the algorithm would build, only it’s specified in Gherkin. Your scenario is now only about b) above - verifying that your program can use the model.
No, the models are very large and complex, and there is a lot of other metadata that is generated prior to the model build itself
You have to upload the (large) dataset, which then gets processed to determine the features it contains, their ranges, etc.
All of this metadata is required, in addition to the model itself, for post-build functionality to work
I’d recommend adding an abstraction layer in front of the model that allows scenarios to test how it’s queried without worrying about how it’s generated.
It's just that the generation of that state would be best expressed through a series of steps equivalent to a BDD scenario
Of course, we can run an entirely separately process to execute scenarios that generate the snapshots
And then the other tests would just have to assume that this has been run correctly by some external orchestration framework we write ourselves
Hi.. How can I transform datatable data? Like I want to get an object where strings are strings and numbers are numbers?
@JJ From what I’ve learned so far, cucumber doesn’t handle data transformations. It’s job is to identify behaviors. So, the feature is what you want to do. like the well-worn ATM example, Dave wants to withdraw $10 from his account. The scenario are the steps to accomplish this goal. I was taught to describe your steps as if talking to a 19th-century person, i.e. how would one accomplish this goals before the computer age.
So, data transformations, UI widgets, software terms, etc. are all irrelevant in this context. Of course, @Gem will tell you, writing cucumber is more of an art than a reproducible science. You’ll have to find what works for you. This is the exact stage I am in; trying to learn what works for me.
might this help: https://docs.cucumber.io/cucumber/cucumber-expressions/#parameter-types ?
I don't think tables fit in there though, you'll likely have to parse it in your step definition ( https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/data_table_interface.md )
I came across the cucumber-expressions and there's defineParameterTypes but yes.. nothign to to explicit table transfoms. It would just be so useful to have numbers come through as numbers and not strings
Do you use jenkins? how do you see progress? The formatter output seems to be buffered (opposed to console.logs) by jenkins until the tests are completed. i.e. if my test takes 20mins, so I don't see anything going on for 20 minutes.
before writing my custom formatter (how?), I figured someone else might've looking into this already?
@JJ (or anyone else) - would you be interested in porting the new DataTable library to JavaScript? https://github.com/cucumber/cucumber/tree/master/datatable
*Thread Reply:* @Aslak Hellesøy just looked a little bit at it. Think its hard to make it work in a untyped language, as you don't specify the type of parameter in the step definition like with java
Is there a way to put tables into the step definition (or is this a good idea?) vs something you 'magically' get passed? ie. Given your feature file is:
When I add the following contacts:
| name | email | age |
| lennart | <a href="mailto:lennart@mail.com">lennart@mail.com</a> | 30 |
| grandma | | 80 |
Then the cuc expression in your step definition might be:
When('I add the following contacts:[contactlist]', function (contacts)
Instead of (currently)
When('I add the following contacts:', function (contacts)
? If we had this possibility - registering custom table types wouldn't need to be any different from other custom data types (e.g. just set the transformer to Contact.fromJson)?
Alternatively, we could pass a datatable type into the options of the step definitions (https://github.com/lenntt/cucumber-js/blob/master/src/support_code_library_builder/build_helpers.js#L54)?
*Thread Reply:* I like the suggestion to make it explicit in the expression @len! Angle brackets don’t mean anything yet, and they could be used to identify a table type (converter). We could also use |contactlist| (pipes) to make it look a bit more like a table. @mpkorstanje @charlierudolph I’d be interested in your thoughts on this.
*Thread Reply:* Braindump:
A strong type system is required. This means given a method f(arg) we should not only be able to figure out the type of arg, if arg is a list we should also be able to find it the list item type. (Currently Java8 Lambda expressions fail this test).
If no type system is available we'll have to build a tiny expression language to describe the same type information. E.g. "map of String to List of Double" or {String: [Double]}.
I am currently thinking that passing this into the stepdef will be most worth while.
*Thread Reply:* E.g. Given("my expression", "list of strings") but I hold no strong opinions on this.
*Thread Reply:* 4 Expressing this type system can be done through a an expression in a string or through methods. E.g. "map of int to double" of map(Int, Double). Depending on what is available in the language.
*Thread Reply:* Owh. Better idea for js.
You we can declare the type as an object {"String": ["Double"]}.
*Thread Reply:* So to summarise - we provide a mechanism to declare the table transform type. This is for languages/syntaxes that don’t have static typing (Ruby, JavaScript) and/or sophisticated reflection (Java8 lambdas).
We haven’t settled on the mechanism, but the suggestions are:
* [...] at the end of a cucumber expression (I don’t really like that, thinking about it)
* a 2nd argument following the Cucumber Expression (or RegExp). The type/structure of this argument is still to be determined (String, Dictionary, other…)
*Thread Reply:* Dictionary --> Object. A list of double is ["Double"] a map of String to Double is {"String": "Double"}.
*Thread Reply:* @Aslak Hellesøy
1) square brackets are just an example, can live with other characters (I don't even see why not just {...}).
2) 2nd argument: there is already an optional 'options' object 2nd argument (https://github.com/cucumber/cucumber-js/search?q=buildStepDefinition&type=Code&utf8=%E2%9C%93).
I'm not seeing the 2nd work doing an automatic transform yet,
(my guess is most of the times, when writing my own transformer, I'll be calling a constructur or something - basic data types wouldn't suffice.)
@mpkorstanje, if we stick to the contactlist example above, what would the second argument look like?
*Thread Reply:* @len - Cucumber Expressions currently have no knowledge of DataTables. It is a standalone library. I think it’s cleaner to keep it dependency-free. That excludes declaring tables in Cucumber Expressions. It’s a bit weird to add it there - it has nothing to do with matching steps.
*Thread Reply:* @len It would look like this: When('I add the following contacts:', ['contact'], function (contacts))
And somewhere else you'd have to register a data table type:
typeregistry.defineDataTableType(new DataTableType(
"contact",
new TableEntryTransformer(entry => new Contact(entry));
));
*Thread Reply:* Think I got it, thanks.
So basically the only difference between the normal CustomDataType and the CustomTableDataType, would then be that the transformer in the latter iterates over all entries? @mpkorstanje
*Thread Reply:* That would depend on the transformer. You can iterate on the individual cells, the entries - (header, value) pairs -, the rows, or the whole table at once.
*Thread Reply:* That'd be TableCellTransformer, TableEntryTransformer, TableRowTransformer and TableTransformer respectively.
*Thread Reply:* These can be combined to some degree:
For example transforming this table to {String: Coordinate}
| | latt | long |
| KMSY | 29.993333 | -90.258056 |
| KSFO | 37.618889 | -122.375 |
| KSEA | 47.448889 | -122.309444 |
| KJFK | 40.639722 | -73.778889 |
Would use the build in TableCellTransformer for String and the custom TableEntryTranformer for Coordinate.
*Thread Reply:* If the table didn't have header you'd have to declare a TableRowTransformer instead.
*Thread Reply:* Ok, cool.
Seems option #1 (building into expressions) is not really an option? (I can still give some arguments for that)? @Aslak Hellesøy
*Thread Reply:* @len if you’re planning to port the library to JavaScript (would be amazing BTW), the right place to do that would be in a javascript directory under https://github.com/cucumber/cucumber/tree/master/datatable
*Thread Reply:* We can then work on integrating it into cucumber-js. How does that sound?
*Thread Reply:* Sounds great, I'll definitely look into it. If I have any, what would a good place to ask questions, this thread?
*Thread Reply:* Let's discuss it in the PR. Slack messages disappear after a while.
*Thread Reply:* Table + type --> json. Doesn't cover everything, but should cover the common parts.
*Thread Reply:* @Aslak Hellesøy @mpkorstanje PR is here, quite rough, but I need to know if I'm on the right track before continuing https://github.com/cucumber/cucumber/pull/385
Anybody experience attaching a json string with long values? The attach function rounds the values.
jsontext = "[{"key":476007500100000067,"request time":"20180503T12:47:39.115Z","response time":"20180503T12:47:39.221Z"}]"
It attaches to the results.json as:
{
"key": 476007500200000100,
"request time": "2018-05-03T12:47:39.115Z",
"response time": "2018-05-03T12:47:39.221Z"
}
BUT if I attach as string then I see the correct key value.
*Thread Reply:* fyi you can wrap multi-line code snippets in triple-backtick ``` for easier reading
*Thread Reply:* like this jsontext = "[{"key":476007500100000067,"request time":"2018_05_03T12:47:39.115Z","response time":"2018_05_03T12:47:39.221Z"}]"
It attaches to the results.json as:
{
"key": 476007500200000100,
"request time": "2018-05-03T12:47:39.115Z",
"response time": "2018-05-03T12:47:39.221Z"
}
I just forked cucumber-js, but I'm new to yarn, work with npm myself.
I ran yarn install. when I do yarn test, it picks up eslint from my path, which i globally installed via npm. and complains about missing plugins, like babel. whats normal practise?
Hmm, installed via npm, get 5 lint errors by prettier/prettier, guess thats not supposed to happen, e.g.
`${this.feature1Path}:1${separator.expected}${this
.feature2Path}:2`
eslint wants it to be:
`${this.feature1Path}:1${separator.expected}${
this.feature2Path
}:2`
This is my go-to site https://yarnpkg.com/en/docs/cli/
it’s just a double-check to make sure you have the latest versions of the packages described in your package.json. You could probably skip it, but it doesn’t hurt and it’s quick.
Anyone got any idea why exceptions can't be caught inside steps? I have a promise rejection that I'm handling, but cucumber seems to be ignoring my handling code.
When('the active scanner is run', async function () {
await (async () => {
await (function setAuthenticationCredentials() {
return new Promise((resolve, reject) => {
zaproxy.users.setAuthenticationCredentials(
param1, param2, etc,
(err, resp) => {
if(err) {
// Anything thrown or rejected here, fails the step.
}
resolve(resp);
}
);
});
}());
await (function setAuthenticationCredentials() {
return new Promise((resolve, reject) => {
zaproxy.users.setAuthenticationCredentials(
param1, param2, etc,
(err, resp) => {
if(err) {
// Anything thrown or rejected here, fails the step.
}
resolve(resp);
}
);
});
}()).then(outcome => onCompletion(outcome));
})();
});
haven't played much with await/async yet. I'm guessing the outer function is async - does cucumber support that?
Why not remove the await and return the promise directly?
And are you sure you call reject?,
return new Promise((resolve, reject) => {
zaproxy.users.setAuthenticationCredentials(
param1, param2, etc,
(err, resp) => {
if(err) {
// Anything thrown or rejected here, fails the step.
reject(err)
}
resolve(resp);
}
);
});
Actually, that's not quite true, there is one more between the step function and the one I pasted, I'll tidy it a bit more
Ok @len, that's it. The two sub functions are identical in this example, there are a few of them, but the structure are currently the same.
It's not a big deal, I'm simplifying (dry'ing) it out currently. I've got a work around for now, but curious to know if this is expected behavior? From the googling I did, it seems to be.
I'd expect cucumber steps to fail if the returned promise rejects properly. I'm not quite convinced yet its cucumber here, but your control flow missing something.
Is it possible your handler calls both reject and resolve?
Are you able to reproduce with a simpler working example?
reject didn't appear to do anything, throw fails the step immediately.
I'm going to put all the functions in an array and map over them... try and simplify a bit.
Hello guys! Quick question, is there any way to use And/But in step definitions? i was using defineStep in cucumber 3 but now i'm using 4 and i'm kinda lost 😛 Thanks!
*Thread Reply:* And, yes - you would simply write the step definition as the parent it belongs to.
For example:
Given I have a condition
And I have another condition
the And here would actually be a Given when you write out your step defs.
Iirc, But is no longer used.
*Thread Reply:* Yeah that's what I'm doing right now, replacing the Ands with Givens, but I was wondering if there was a way to add it so the step is And(/^bla bla$/)
thanks! 😄
*Thread Reply:* Perhaps you mean https://stackoverflow.com/questions/50104494/cucumberjs-and-gherkin-why-can-not-i-use-and-and-but-steps/50249795#50249795 ?
Hello all,
I’m new to CucumberJS and having problem that cannot solve 3 days now 😞
I’m having nodejs 10 project with cucumber 4.2.1, selenium-webdriver 4.0.0-alpha.1 and opencv4nodejs 4.4.0 When I run my feature file, All steps in all scenarios are run simultaneously without waiting each other. As a result 6 instances of FF start immediately after running my feature file. I haven configured anything (intentionally) to run scenarios in parallel.
*Thread Reply:* @Yakim Rachev my first guess: async selenium js is async, so either your tests need a properly resolving promise or use a callback on the step definition
*Thread Reply:* Hi @len. Thaks for the quick reply. I'm aware of selenium async nature, and in my words.js file I call selenium functions with await.
*Thread Reply:* are you able to share a sanitized config file for your cuke and selenium setup?
*Thread Reply:* while i haven’t tried using async/await @Cat, i am having success just using promises.
*Thread Reply:* assertions not resolving promises were giving me grief. using chai-as-promised and asserting, say:
element.getText().should.become(text, 'The text did not match:');
*Thread Reply:* Hi there. I think I’ve got the problem… As I said I’m new to CucumberJS (also to NodeJS). In my step definitions was not returning the result from the webdriver methods call. I went to nightwatch-cucumber, now and the thinks happens more easy. Thanks all
correct me if i’m wrong, but it seems one cannot debug (in, say, WebStorm… others are probably similar…) when --parallel is set?
When I clone cucumber-js, do an npm i and then npm test i am getting linting errors. when I run npm run lint-autofix to correct those linting errors I get a failing Scenario: Scenario: extending SummaryFormatter # features/custom_formatter.feature:61. Any thoughts?
*Thread Reply:* I get more failures when running on windows and I have to update the package.json to have "set BABEL_ENV=browser;
*Thread Reply:* In order to check my sanity I created a Docker container running ubuntu 16.04, npm 5.6.0, and nodejs 8.11.2, that is when I still get the linting errors and after the auto-fix I still get the one failing scenario.
Actually, I am working with cucumber in serenity-js and I need to work with the words Feature, Given, When, Then in spanish, I was testing with " # language: es " but this didnt work , How to can setup the protactor files or serenity-js files for use this feature?. Thansk for the help
I am wondering if someone can help me, I am looking to turn our framework in a node module, in doing so, i need to split the "feature" file folder and the "step-definitions" folder, but i don't seem to be able to work out how to set this via arguments on run? am i missing something or can it not be done?
*Thread Reply:* If I’m understanding the question correctly, you’d be able to simply pass the step defs folder into the require arg and just point to the features directory
*Thread Reply:* https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md you’ve followed this doc?
*Thread Reply:* '/nodemodules/cucumber/bin/cucumber.js --require ./nodemodules/sc-caf-module-test/test/features/step-definitions --tags @component ./tests -f json:./tests/reports/cucumber-report.json'
*Thread Reply:* Based on that doc I sent, it looks like your step defs should be passed through as : <DIR>/****/**.js
*Thread Reply:* although if you’re keeping it in the features dir it could just be: features/****/**.js
*Thread Reply:* ok, ill continue to play, as i have tried what it is saying in the doc, i guess im just missing something....
*Thread Reply:* np - out of curiosity, is your support code JS browser compatible? Or is it es6, etc?
I'm having an issue when running the cli more than once in code. I get "Cannot read property 'stepDefinitions' of undefined". It doesn't seem to matter if I create a new cucumber.Cli(args in here)
When I try spawning a process as I used to here https://github.com/cucumber/cucumber-js/issues/786#issuecomment-372928596 , I get: stderr: Error: Cannot find module
Bringing a discussion here from #help.
Context:
I am trying to pass an environment variable to my Cucumber test suite. So I can setup my tests with it on different environments.
// In my steps
if ( this.env === 'production') {
url = '<a href="http://www.production-site.com">www.production-site.com</a>'
} else {
url = '<a href="http://www.stage-site.com">www.stage-site.com</a>'
}
The script I am running is not giving me the environment variable I need, I.e this.env = undefined. This is the script:
cucumber-js --world-parameters "{\"env\":\"production\"}"
the \ are used to escape "
*Thread Reply:* Bump of desperation. Does anyone have experience in world-parameters?
*Thread Reply:* I haven't used them, but what you could try is passing system environment variables instead?
TEST_ENV=production./node_modules/.bin/cucumberjs ...
(depends a bit on your setup and OS) then in your code:
if (process.env.TEST_ENV === 'production') ...
*Thread Reply:* @len Nice, that helped.
This is my package.json for those who may be facing similar problems.
"scripts": {
"test": "cucumber-js features",
"test-prod": "TEST_ENV=production npm run test",
"test-stage": "TEST_ENV=development npm run test"
},
then in my hooks.js
if (TEST_ENV === 'production') {
// Do prod setup
} else if (TEST_ENV === 'development') {
// Do dev setup
}
Are you using a custom world constructor? The world parameters get passed to it: https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/api_reference.md#setworldconstructorconstructor
Hi Friends I need you help Actually, I am working with cucumber in serenity-js and I need to work with the words Feature, Given, When, Then in spanish, I was testing with " # language: es " but this didnt work , How to can setup the protactor files or serenity-js files for use this feature?. Thansk for the help
Hi all. Is there a to add properties to the json report besides the result of the test.
E.g.
"steps": [
{
"arguments": [],
"keyword": "When ",
"line": 4,
"name": "I register with phone number '6623471507'",
"match": {
"location": "support/steps/customer/auth.js:5"
},
"result": {
"status": "passed",
"duration": 6000000,
"request": "..." <-- Custom property
}
},
Not much of a Js user. But you can write your own formatter. Though I think you're looking for something like scenario.write.
Cool! Thanks @mpkorstanje I think scenario.write may work. Do you or anybody knows how to use it in cucumber-js?
The docs for js don't include examples. https://docs.cucumber.io/cucumber/api/#hooks
But you can put a debugger on it an see what methods scenario has
And perhaps send a PR once you've figured it out to improve said docs. 😄
@Alonso I don't think you can change the results the built-in json formatter writes back directly (if I'm wrong, please correct me!!),
but perhaps you can workaround with this: https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/attachments.md
I wouldn't mind a better solution to set, for a similar case, fill metadata property on a feature, e.g. to use https://github.com/wswebcreation/multiple-cucumber-html-reporter#metadata more directly.
*Thread Reply:* @mpkorstanje takes a while to get used to - I was in the cucumber-js docs like 'WHERE IS CUCUMBER-EXPRESSIONS' 🙂.
"steps": [
{
"arguments": [],
"keyword": "When ",
"line": 5,
"name": "I send request to get product offers",
"match": {
"location": "support/steps/customer/offers.js:6"
},
"result": {
"status": "passed",
"duration": 18000000
},
"embeddings": [
{
"data": "POST /offers",
"mime_type": "text/plain"
},
{
"data": "{}",
"mime_type": "application/json"
},
{
does multiple-cucumber-html-reporter print these or do you know any html reporter that renders them?
yeah, multiple-cucumber-html-reporter prints them, so do most others, like https://github.com/gkushang/cucumber-html-reporter
Sorry for newby question, but how do we turn on the cucumber-report.json in cucumber.js? I see this: https://github.com/john-doherty/selenium-cucumber-js/blob/7238c9bf966bab0ca0805445130c7754fb5e14aa/index.js#L100 but I'd like to get reports going on https://github.com/Adezandee/cucumber-mink
*Thread Reply:* @Vaene I dont understand the question, do you want want a json report output? or use cucumber-mink? (I dont think those two are related?)
I can probably only help with the first one. How do you run your tests now?
*Thread Reply:* Hi Len, thanks for the reply. Yes I just want to setup cucumber to write cucumberreport.json by default. I can do it via command line now (figured it out after I posted) with: npx cucumber-js --format json > ./reports/cucumberreport.json features/my-smoke.feature
*Thread Reply:* The selenium links is just by way of example of how they are handling it. I like everything about the selenium-cucumber, I just like the access to the mink step definitions that cucumber-mink has.
*Thread Reply:* Reminds me of web_steps, be aware, danger ahead: http://aslakhellesoy.com/post/11055981222/the-training-wheels-came-off
*Thread Reply:* Yeah I gotcha but the Gherkin appeal is also so non programmer stake holders can write simple tests in their tickets to see basic functionality replicated. 85% of what we do falls into this boring training wheel area, the rest we can handle with more specialized mocha, etc tests
*Thread Reply:* What I'd like to do is have the test run, output a cucumber_report.json, and then have cucumber-html-reporter render that in pretty html. the selenium repo does that automatically, I am trying to replicate that functionality in the mink repo.
The world parameters are an alternative to env variables. Docs on world: https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/world.md#world, features with examples: https://github.com/cucumber/cucumber-js/blob/master/features/world_parameters.feature
Hey @channel - please vote on Cucumber Expression/Parameter Type support in WebStorm: https://youtrack.jetbrains.com/issue/WEB-31420
Hi... I am having a strange problem. I setup some tagged hooks for setting up and cleaning test data for some scenarios. Thing is that if a scenario that uses those hooks is the last one to be executed, the after hook won't run... Has anyone seen that?
Hi, we want to use the Cucumber for android and we want to be sure that it will continue to be supported for future years, from what info we can know this kind of thing ? That it will continue supporting running with Espresso and other frameworks ?
@David Arshavsky Cucumber for Android is written in Java - did you mean to post this in <#C5YHPPJMP|help-cucumber-jvm>?
*Thread Reply:* While kotlin is interoperable w/Java and Android, the javascript channel probably isn’t the place to post? 🙂
*Thread Reply:* Just want to be sure that Cucumber will will work with all platforms for years to come
*Thread Reply:* We have more then 20 teams that stating using it and we need to know that in 1 year it will still work on all platforms and be supported, who can help me to understand this?
*Thread Reply:* @David Arshavsky we’re building a company around the open-source product. I’m one of the original OSS contributors, a co-founder of the company and the CEO. We don’t intend on going anywhere 🙂
*Thread Reply:* @David Arshavsky that said, we rely on contributions from the community to keep things going. We recently stopped supporting some Cucumber-JVM modules because we didn’t have bandwidth to support them: https://cucumber.io/blog/2018/05/19/cucumber-jvm-languages-support
*Thread Reply:* I suggest we move this conversation over to <#C5YHPPJMP|help-cucumber-jvm> since this doesn’t seem related to JavaScript/Cucumber.js
*Thread Reply:* As you can see from the stats in that post, Cucumber-Android accounts for 0.14% of the usage of Cucumber-JVM. Since you have 20 teams using Cucumber-Android, would you consider giving something back to the community by encouraging some of these developers to contribute to Cucumber-Android? That’s the best assurance you can get that it will stick around.
*Thread Reply:* The teams mostly using it for web and some for iOS, now we wanted to try it on Android as well, so I understand that you stop supporting because low numbers of usage at this point. I will speck with our QA leads and see what they say about supporting. Any numbers on iOS?
*Thread Reply:* Our intention is to continue to make new releases of Cucumber-Android ad the underlying Cucumber-JVM evolves. How long we’ll be able to do that depends on contributions from users. How many people use it without contributing doesn’t affect the decision as much.
*Thread Reply:* There is no official Cucumber for iOS, but there is a semi-official one that the Cucumber team doesn’t maintain. See http://docs.cucumber.io/installation/ and https://github.com/Ahmed-Ali/Cucumberish. It’s also in need of new maintainers. I don’t have any downloads stats for it.
*Thread Reply:* So I understand that your team focus at this moment are more for web then Android /iOS ?
*Thread Reply:* Our main focus is on 4 implementations: Java, JavaScript, Ruby and .NET. No Cucumber implementations know anything about the Web (HTTP,DOM etc). People can use any of the implementations to test web applications, but you need to add additional libraries to the mix for that (Selenium WebDriver being the most popular one). Cucumber doesn’t know or care what UI automation library you use to interact with a UI.
*Thread Reply:* ^^ to expand on that: There’s nothing stopping you from using appium/its equivalent in conjunction w/Cucumber. Same as any other runner.
Hi Folks! I need a help, I am unable to open a web page (I have just started using the Cucumber).
_stepdefination.js__
this.Given(/^I am on the login page$/, function (callback) { browser.get("URL").then(function(){ callback(); // })
});
*Thread Reply:* Unhandled rejection ReferenceError: Given is not defined
*Thread Reply:* How and where to define Given? 😞
Can you please just put a code here to open any web-page? (for e.g. google.com)
*Thread Reply:* ```_stepdefination.js__ import { Given } from 'cucumber'; this.Given(/^I am on the login page$/, function (callback) { browser.get("URL").then(function(){ callback(); // })
});```
*Thread Reply:* Still not working!
import { Given } from 'cucumber'; Given(/^I am on the login page$/, function (callback) { browser.get("https://www.mysite.com/").then(function(){ callback(); // })
});
*Thread Reply:* Many errors, I can see..
Unhandled rejection /home/ttpllt21/Desktop/cucumber/stepDefinitions.js:1 (function (exports, require, module, _filename, _dirname) { import { Given } from 'cucumber';
*Thread Reply:* node version / loader? try
const Given = require('cucumber').Given:
*Thread Reply:* Thank you all, but, still, nothing is working.
I am running it with Protractor
_conf.js_ exports.config = { directConnect: true, framework: 'custom', frameworkPath: '/home/ttpllt21/nodemodules/protractor-cucumber-framework', capabilities: { 'browserName': 'chrome' }, cucumberOpts: { format: "summary" }, specs: ['./**.feature'] };
--------home.feature--------- Feature: Homepage
Scenario: Visit Homepage Given I am on the homepage
------step.js------------
const Given = require('/home/ttpllt21/node_modules/cucumber').Given(/^I am on the login page$/, function (callback) { browser.get("https://www.mysite.com/").then(function(){ callback(); // })
});
*Thread Reply:* nothing is working is not enough for us to help debugging 😉
Did you turn on your pc? 😈
*Thread Reply:* Yes! PC is on! 🤣 script is not working, I am just new and have no basic idea about cucumber, I have tried to read articles and none of them helped.
*Thread Reply:* @Aasim Anwar I recommed you read this then ask again: https://opensource.com/life/16/10/how-ask-technical-questions
G'day mates!
Currently looking into cucumber-js to start BDD'ing a large react app - running into some resistance with setting up the project.
Is therea place to start with documentation how to set up a project to test with cucmber-js, react, babel etc.?
Any help greatly appreciated!
(and thanks for the library...sweet as!!)
*Thread Reply:* the babel docs are pretty thorough as far as setup if you’re wanting to use ES6
regarding cucumber-js, I'm having some trouble debugging a migration from v1.3.3 to v2+, it seems that by upgrading the cucumber version, the simple test I made for a PoC is not detecting step_definitions anymore. v1.3.3 properly detects them
For the moment it works with 1.3.3, but it would be great to have it running on a recent 3x-4x
*Thread Reply:* try to require step definitions exactly
require: './step_definitions/****/**_steps.js', => require: './step_definitions/login/login_steps.js',
*Thread Reply:* and it may have to be array, so require: [ './step_definitions/login/login_steps.js' ],
*Thread Reply:* It does not appear to be that as I've tried with or without wildcard**s and under array form.
*Thread Reply:* I remember having to change this.When(... to When(... (where when is required from cucumber)
*Thread Reply:* I'll try refactoring the steps when I have time, currently I've decided on 1.3.3
Hi I have a problem with arguments passed to a function from step definition
when i try this defineStep('accedo al movimiento "{string}" del producto "{string}" y pantalla "{string}"', async function (movimiento, producto, pantalla) { await goToMovements()}); async function goToMovements(position, page, route = '') { ... }
but when i try this defineStep('accedo al movimiento "{string}" del producto "{string}" y pantalla "{string}"', goToMovements);, Cucumber throws this error function has 2 arguments, should have 3 (if synchronous or returning a promise) or 4 (if accepting a callback)
if i set route argument to simply route in stead of route = ' ', success but if I leave with default value, failed
Hmm, thats very odd. I think that has to do with how the function is transpiled to javascript. Not much workaround aside from not using a default parameter. You could also use something like https://www.npmjs.com/package/util-arity to wrap your function in one that ha a specific length
Beside being a very interesting read https://eslint.org/blog/2018/07/postmortem-for-malicious-package-publishes Caused quite some noise at some offices this morning ^^
Be aware there's a timeslot you could've pulled this in locally when working on cucumber or other projects with eslint.
when I am excuting this test its executing with top 3 test data but not with last one
spaces would be… ideal, actually because that would be readable but that’s a style thing 😛
if the screenshot isn’t an accurate depiction of your code, there’s really not a whole lot I can do
Examples:
|Account_search|URL|
|SUZANNE CZARKOWSKI|xyz|
|617-543-8719|xyz|
|8499100020187174|xyz|
|8499100020187174|xyz|
while executing i can see my test with three different test data but not with fourth one
If that’s the case, then it’s likely just related to the speed the tests are running at if you aren’t getting any errors at all
Ideally, you want tests to run as fast as possible (which means watching the UI isn’t generally a goal unless you’re troubleshooting)
If you absolutely, positively, MUST see each and every test case execute via UI? Add waits to your protractor scripts. It’d be poor design, but it’ll do the thing you want 🤷
Unless cucumber is simply ignoring duplicate test cases (which iirc, it doesn’t do but I could be mistaken given that you’re using a much older version of cucumber), you’re likely just going to need to modify your protractor scripts if it HAS to be visible in the UI for some reason.
My comment was simply that I’m not as familiar with the older version because my stack uses the most recent.
There could be differences in behavior that I’m unaware of since it’s a significantly older version of cucumber
Although I would suggest not repeating test cases - you could try changing case 4 to a different data point to see if you can watch it
plus makes for better tests since there’s usually not a good reason to duplicate test cases.
even if in your system, those represent two distinct values (e.g., mail id = abc and account number = abc - different key/value pairs but happen to have the same value), cucumber doesn’t know that. As far as it’s concerned, you’re just entering a string value.
Hey Folks, hope all doing great...
Quick help, pls can anyone assist me to add IE11 into the wdio cucumber framework selenium standalone server - 3.4.0 node: 6.9 let me know if you need any more detail
*Thread Reply:* What’s the issue precisely? are you unable to add the driver?
*Thread Reply:* thanks Cat for your response. I was facing issue while running test on IE11 . Issue has come up after adding driver as it was asking to add gecho.
Issue is resolved now. Thanks a lot:)
Did anyone experience errors with webdriver-manager update command today
The error I see is: $ webdriver-manager update events.js:160 throw er; // Unhandled ‘error’ event ^
Error: getaddrinfo ENOTFOUND selenium-release.storage.googleapis.com selenium-release.storage.googleapis.com:443 at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
I’ve been using this framework for testing some applications that use Angular as well as legacy applications. https://github.com/igniteram/protractor-cucumber-typescript
I’m about to start diving into ReactJS, and I wanted to check if anyone had any good suggestions for testing that, or if I should try to get it working with the framework I’m already familiar with.
howdy y’all — i have a conundrum! I’m using Selenium and Cucumber to test a React app. the app subscribes to a websocket that notifies when data has been updated on the backend, so the client can initiate an AJAX call to an API to refresh the UI with latest data — and therein lies the problem
** https://cucumber.io/blog/2014/03/03/the-worlds-most-misunderstood-collaboration-tool
this AJAX update is intermittent, unpredictable, and problematic. one of our steps opens a data filter, manipulates it, then applies the filter. but, if an external update is initiated mid-step, the UI refreshes, and the filter dropdown is closed — that step fails.
i’d like to have a method to listen for the update, pause the current step, and continue/restart the current step once the update has completed — much like a conditional breakpoint on a debugger
caveat(s): the websocket is protected by authentication, and cannot be snooped or sniffed to my knowledge
Anyone able to get Webstorm and or Intellij to recognize step definitions in typescript?
Hi! Can you help me?
On Ubuntu Server/nodejs 10.9.0 I start that test cucumber-js --require-module babel-core/register -f summary -f json:reports/cucumber_report.json --language ru features/test.feature and catch that error
(node:9711) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
TypeError: Cannot read property 'line' of undefined
at Object.generateEvents (/home/test/api-bdd/node_modules/gherkin/lib/gherkin/generate_events.js:61:38)
at /home/test/api-bdd/node_modules/cucumber/src/cli/helpers.js:53:26
at Generator.next (<anonymous>)
at Generator.tryCatcher (/home/test/api-bdd/node_modules/bluebird/js/release/util.js:16:23)
at PromiseSpawn._promiseFulfilled (/home/test/api-bdd/node_modules/bluebird/js/release/generators.js:97:49)
at /home/test/api-bdd/node_modules/bluebird/js/release/generators.js:201:15
at getTestCases (/home/test/api-bdd/node_modules/cucumber/lib/cli/helpers.js:102:18)
at /home/test/api-bdd/node_modules/cucumber/src/cli/helpers.js:32:13
at Generator.next (<anonymous>)
at Generator.tryCatcher (/home/test/api-bdd/node_modules/bluebird/js/release/util.js:16:23)
at PromiseSpawn._promiseFulfilled (/home/test/api-bdd/node_modules/bluebird/js/release/generators.js:97:49)
at Promise._settlePromise (/home/test/api-bdd/node_modules/bluebird/js/release/promise.js:574:26)
at Promise._settlePromise0 (/home/test/api-bdd/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/home/test/api-bdd/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/home/test/api-bdd/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/home/test/api-bdd/node_modules/bluebird/js/release/async.js:143:10)
But on my Mac I don't catch that error
I created issue about it https://github.com/cucumber/cucumber-js/issues/1117
Hi, I was hoping if someone here can share with me an example of how to setup a debugger for CucumberJs when used with Typescript in VSCode. I cannot get it to work
Hello all, are there any afterstep or beforestep blocks? I want to do something after eachstep, like collect data or take screenshot. I am using cucumber-js
*Thread Reply:* I am not able to get it working...setting tags in the hooks is same as defining a tag. needs to be invoked by explicitly declaring the tag in the feature file.
*Thread Reply:* After({ tags: 'not @deleteParticipant' },(scenario){//do something}
*Thread Reply:* I have few After hooks with tags, as such
Before({tags:'@setup', async(){
//does something})
After({ tags: '@teardown' }, async () => {
//does something}
which is called in a feature file as such
@setup @teardown
Scenario: Do something
I also have an after hook with no tags, which runs after each scenario
After((scenario){//take screenshot}
I need to take a screenshot when a step fails in the scenario.
*Thread Reply:* The above works great as long as i dont have the @teardown tag in the scenario. The screenshot is taken at the step it fails.
*Thread Reply:* For scenarios that have the @teardown tag, the screenshot is taken at the end of tagged after hook, @teardown
*Thread Reply:* What i am trying to do is to see if i can take the screenshot at the time of step failure, instead of scenario failure.
*Thread Reply:* Ah, gotcha. I'm not sure the best way to navigate that. I do know that the scenario object that gets passed in to the hooks contains the info around what tags it has as well as its success/failure, so perhaps you could modify the hooks to instead perform actions based on particular tags?
*Thread Reply:* now that i think about it..it might not work. The After hook with no tag runs after the complete scenario, including @teardown. I might be wrong, but will let you know 🙂
*Thread Reply:* You could just have your scenario.failed? check happen before teardown and theoretically be golden. 🙂
*Thread Reply:* Thanks so much @Gem! i was able to find a solution using your suggestion.
*Thread Reply:* The first line of that link is literally “World is an isolated context for each scenario, exposed to the hooks and steps as this. ”
Hello! Cucumber is Parallel, any good reading material on how to best implement this?
Cucumber doesn't run in parallel and I would imagine that this is a specific choice that @Aslak Hellesøy and others made. There are tools out there that will help you accomplish concurrency, but you should probably look into what's prompting you to want to run in parallel first.
If you've got long running scenarios, is it because you're possibly automating through a UI which is slow, or perhaps there are time saving steps available in your system not being used or can be built into your code to make things more testable? It's also worth looking into the scenarios you've written to see if they're testing too many things rather than very specific & concrete examples.
Ahh ok, the application we are testing is quite big, most of the scenarios are pretty specific and concrete, but they add up very soon.
You can get parallelism through node child process. I customised a script for my project to spawn cucumber child processes to target different browsers and platforms at the same time.
But its a tideous task and I would also suggest to do some research as to what’s the requirement at your end that you want to automate in Parallel
@arjunjh10 Thank you! I will look into that. Was it tedious because it was a lot of setup or maintenance?
if it was setup, i think it might be worth the effort. The application i am testing is in its infancy, but already big enough. Granted, we will be removing some of the scenarios as it grows, i still think having the testing run in parallel might be a good option
For someone who was new to the concept child processes, it was a bit of a learning curve. And also, parallelism brings about more maintenance and setup.. simple 1 process cucumber testing is like 3-4 step setup
Ok, to be fair, in our case, when I say parallel, it means running same test on different platforms or browser configs at the same time..
Definition could vary, and you may wanna run different scenarios together …
> the whole suite takes about an 1hr 30 mins oh wow.. thats lot of time
What scenarios of yours take the longest and why do you think that is?
we have two suites that we run..smoke and regression. regression is done overnight and that's the one with 1.5hr run time. most of the time is because we are running against large data set, where we are expecting certain number of rows, depending on some business logic. this can be anywhere from 20-25 rows
In that case, I’d consider leveraging your own api to hit endpoints for the bulk of the data handling, that will allow you to speed up the UI testing itself. It also allows you to more easily isolate the components you’re testing.
Does cucumber support running the tests programtically from Node.js without using the cli
I want to run a test multiple times and each time change some configuration
I’m not seeing explicit docs for running it in node, but we do it. Do I remember where I read that I could do this? No. 🤷
We’ve also got a custom command line runner for the entire framework in here, but it’s not really relevant for this use-case in particular
*Thread Reply:* @Cat Hello again, is there a way I can tell cucumber not to process.exit
*Thread Reply:* iirc, cucumber exits by default when the event loop has finished draining. I’ve not had a need to do this, so I’d suggest looking at the CLI code for this one
*Thread Reply:* Oh sorry I just had bug in the output 😥 it actually doesn't exit by itself. Thank you 😄
*Thread Reply:* (don’t laugh - I legit just used it this morning already for some weirdness I was seeing - turned out to be a Babel issue)
*Thread Reply:* Hi again, I'm using this and it's working great with all my requirements except that when I try to pass the --parallel option it gives me an error
*Thread Reply:* do you think it should work if we run the cucumber.Cli like this
*Thread Reply:* of course I checked that I don't have any writes to the console
*Thread Reply:* keep in mind --parallel is experimental (if I recall correctly - one of the others may correct me on that)
That said: you’re still accessing the CLI fundamentally (it’s how you’re passing in your requirements, configs, etc), but those can be easily made dynamic so that you can quickly swap things out for distinct runs
I need your help in implementing BDD scritps for canvas based elements on the page
So: cucumber is a test runner, not a webdriver. You can’t use cucumber itself to inspect anything - cucumber is just running the tests
*Thread Reply:* Cypress is great! I use this (below) tool to combine these two amazing tools! https://github.com/TheBrainFamily/cypress-cucumber-preprocessor
I need a little more context than that. What are you doing that causes that error?
*Thread Reply:* I’m not able to dig into the stacktrace right now, but I’m wondering if the fact that you’re returning cucumberCli.run() may be causing some issues (I could be wrong - just a hunch based on glancing at the code)
*Thread Reply:* it returns a promise so I need to listen to it to know when the tests have ended
See these docs for the latest way to attach: https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/attachments.md
Hi 👋 I am using cucumber v4. An exception thrown in BeforeAll hook crashes the whole run. Please advise, is there any event/handler available for this case? So if an exception takes place, I want to be notified of that, close other processes (configuration server, connection to remote report dashboard, etc.) and only after this to stop the run. Found similar issue (in relation to afterStep), though it was 2 years - https://github.com/cucumber/cucumber-js/issues/658. Guess, things have changed since that time. Any advise will be highly appreciated 🙂
@vadym romaniak can you share your code (just the hook) and the output?
Hi @charlierudolph, please let me know if you need more details
hook.js:
BeforeAll(async () => {
throw 'Some error';
});
output:
[2018_09_05T15:35:30.833] [WARN] default - {"type":"pickle","uri":"features/smoke/login.feature","pickle":{...}}
[2018_09_05T15:35:30.835] [WARN] default - {"type":"pickle_accepted","pickle":{...},"uri":"features/smoke/login.feature"}
[2018-09-05T15:35:30.836] [WARN] default - {"type":"test_run_started"}
[2018_09_05T15:35:30.843] [ERROR] default - Unhandled rejection VError: a BeforeAll hook errored, process exiting: features/support/hooks.js:165: Some error
at /Users/Documents/Projects/js/node_modules/cucumber/src/runtime/index.js:36:15
at Generator.next (<anonymous>)
at Generator.tryCatcher (/Users/Documents/Projects/js/node_modules/bluebird/js/release/util.js:16:23)
at PromiseSpawn._promiseFulfilled (/Users/Documents/Projects/js/node_modules/bluebird/js/release/generators.js:97:49)
at Promise._settlePromise (/Users/Documents/Projects/js/node_modules/bluebird/js/release/promise.js:574:26)
at Promise._settlePromise0 (/Users/Documents/Projects/js/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/Users/Documents/Projects/js/node_modules/bluebird/js/release/promise.js:694:18)
at _drainQueueStep (/Users/Documents/Projects/js/node_modules/bluebird/js/release/async.js:138:12)
at _drainQueue (/Users/Documents/Projects/js/node_modules/bluebird/js/release/async.js:131:9)
at Async._drainQueues (/Users/Documents/Projects/js/node_modules/bluebird/js/release/async.js:147:5)
at Immediate.Async.drainQueues (/Users/Documents/Projects/js/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:810:20)
at tryOnImmediate (timers.js:768:5)
at processImmediate [as _immediateCallback] (timers.js:745:5)
[2018-09-05T15:35:31.847] [WARN] default - [15:35:31] E/launcher - BUG: launcher exited with 1 tasks remaining
@vadym romaniak that is by design. If a before all hook fails, the entire suite can’t be run
But no scenarios would be run. I’ll think on this a bit as this wasn’t put into the normal flow as we didn’t have a way to report a before all hook error
@charlierudolph That would be great to have an error when before all hook fails. Should I open an issue? > I guess we can report the error without killing the suite
howdy all! i am writing a custom task runner around Cucumber for Node, and i am wondering — when passing CLI parameters to a Node child_process.exec, does Cucumber need to have --parallel in a particular position?
*Thread Reply:* Can you give an example of what you’re doing in particular? I don’t think it should need to be in a particular position
*Thread Reply:* i am passing through additional command line variables to allow configuration by TeamCity of various test configurations
*Thread Reply:* afaik, there’s no reason it would need to be passed in a particular order, or drop the params.
*Thread Reply:* but a custom value — say --target dev is swallowed somewhere when --parallel 25 or whatever is provided
*Thread Reply:* it only seems to be the ’--target` option. others pass through fine.
i am noticing that other --params seem to be dropped when --parallel is included or not, but not sure what the order should be — or if it matters
Hi Folks...I wonder is it possible to get all the test scenarios in a test run in the BeforeAll stage of the current test run with cucumber-js!?
*Thread Reply:* Integration with Testcafe...I building off this project https://github.com/rquellh/testcafe-cucumber but I'd ideally like to move the setup to Testcafe to BeforeAll rather than Before stage
*Thread Reply:* Reason for moving to that stage is because setting up at Before for every test scenario is really slow
*Thread Reply:* So prior to invoking test cafe I'd like to generate the same number of testcafe scripts as is in the current test run with cucumberjs
*Thread Reply:* I think I’ve got you (although haven’t worked w/testcafe so bear with me). I’m not sure if you could actually grab a list of scenarios going into the run you’re executing since BeforeAll() doesn’t have the same context readily available as Before() but I don’t see any reason you couldn’t set up a fairly straightforward file reader to do the trick.
*Thread Reply:* I guess I could even use the gherkin library shipped with cucumber to get all the tests in a folder...it gets complicated tho if figuring out what tags were applied to the runner too & what tests not to generate... appreciate any pointers on the above
*Thread Reply:* hm. Since you can’t access world context from there, perhaps something that captures the args you use at CL and filters the file matching that way?
*Thread Reply:* I guess I could put the CL arguments into an environment variable & use it back at that stage...it does seem cumbersome tho 😔
*Thread Reply:* a bit. There may be a more clever way to implement it but that’s significantly different than how I’ve been using the BeforeAll + AfterAll hooks so I don’t want to give some super-simple sounding answer if it’s not remotely helpful 😂
*Thread Reply:* In any case it's defo not possible to get that info from BeforeAll...I know this isn't a typical use case but it's just to have integration with Testcafe
*Thread Reply:* it’s not impossible to get it. It’s just a bit of heavy lifting 🙂
*Thread Reply:* But by default from the framework cucumberjs it's a no!?
*Thread Reply:* Correct. BeforeAll & AfterAll aren’t designed to have access to the world instance because they run before everything.
Why not just write a helper function to pass the string from the file to the step?
I suspect the way to go there would not be the before step, but instead passing it into the world instance
so how am I going to know inside the step what is the value for that step
but in the step I do this.selectors and I get an array of all those values
and a step doesn't always have the same position so I can't do this.selectors[1]
There are a couple of different approaches you could use. Ideally, you’d just use the page object model but we aren’t always able to take the ideal route 🙂 In this case, I’d write a helper to pass in the file values (either into the world or into steps themselves if needed, depending on limitations) and then match the value you use in the feature file
I just wanted to know if I coudln't pass it in the arguments so that the other devs don't have to call it each time
I wouldn’t pass it in step args - I’d pass it in step helpers or as a before setup step
Because I see there is an arguments array so I thought that was the solution
Yeah, I think in this case, a helper is prob your best friend 🙂 Even if you leverage it as part of a Before hook, it’ll allow you to more easily destructure and manipulate the data faster/more efficiently
Hm. Trying to figure out the best way to explain without sending you a bunch of code 🤔
ok, so, we have a factory class (we’ll just call it Factory for now) where we can initialize page objects and less page-specific functionality
so if we have a helper where we want to ensure the context remains consistent so that if I have a step that needs to be something akin to return this.client.waitForVisible(this.myElement); and if I want to read in that file so that I can grab whatever’s mapped to this.myElement
(sorry, doing this while working in a completely different part of codebase so bear with me for slowness)
This is a suuuuuper high level explanation but this would allow you to pass it through to your steps so if you had a step where the def was return this.driver.waitForVisible(this.elements.elementName); (or possibly this.elementName depending on how you destructure etc.
this is the world instance and elements is all the elements in the scenario but how could I know which one is the element in the current step
because if you’ve made this.elements (which is the base object of your file import - let’s assume for the sake of this hypothetical that this is, say, a JSON object - something like { elementName : elementSelector, myButton : .button-class, etc.} you would be able to access this.elements.myButton
Hi Guys, I need help. I have a protractor-cucumber-framework. Whenever I run my feature files I get an Undefined. Implement with the following snippet. I have given proper paths to stepDefs. I'm not sure why this is happening
*Thread Reply:* @Cat Hi Cat, I just saw this reply after logging in after some time. Thank you for replying, although I got a co-worker's help to figure this out. But again, thanks for volunteering to help
Hi! "Guys" is easily replaced with the more gender-neutral "Folks", "All" or "Foolish mortals". We'd appreciate if you tried to use that. Thanks!
I don't know much about cucumber JS. But maybe Cat can help you out. She knows more about it then I do.
*Thread Reply:* Cucumber doesn’t capture screenshots. Your webdriver does that.
*Thread Reply:* If you want a screencap at every step, you could just wrap it so that screencap happens after promise is fulfilled by the test step
*Thread Reply:* some discussion here: https://github.com/cucumber/cucumber-js/issues/997]
*Thread Reply:* ^^ correct. That’s why I was thinking perhaps wrapping the steps themselves (perhaps at defineStep?) as promises and capturing the screenshot when they resolve would do
*Thread Reply:* Sometimes I know things, bringing it to a total of like 8 things I know! 😄
Hi, friends! I’m going to dive into using EmberJS with cucumber. Did you try that? Let’s talk about that.
*Thread Reply:* Currently sniffing at https://www.npmjs.com/package/ember-cli-yadda
*Thread Reply:* I’m also writing Ruby, and tests run there, as well, so it could be something along these lines: http://trianglegrrl.github.io/ember-cucumber-pres/#/
*Thread Reply:* I’ve got nothing much to add, but just wanted to chime in that we use Ember and dig Cucumber, too (though we don’t use Cucumber with Ember at the moment)
I am trying to get cucumber.js working on a Create React App. Are there any guides or example projects that can lead me in the correct direction?
*Thread Reply:* How it works on a Create React App is going to be the same way it works on any other app. Cucumber doesn’t care about your framework 🤷 What is the exact problem you’re trying to solve?
*Thread Reply:* The problem my team is facing is using react components with the stepdefs.js file. When we run the cucumber tests, we get an unexpected identifier at “import React, { Component } from ‘react’”;
*Thread Reply:* This import is located on the React component, we are testing. (Apologies for the lack of information, on my phone).
*Thread Reply:* ok, when you’re on your machine, ping me and send some of the code (sanitize it if you need to) for how you’re attempting to initialize the tests and access the app
*Thread Reply:* Ping! The issue we were having is we weren't transpiling ES6 Imports and React JSX. The issue was solved by using the following NPM packages: @babel/core, @babel/cli, @babel/preset-env, and @babel/preset-react. We are still having issues using React CSS imports (Node doesn't like the CSS syntax), ~but taking out those imports allow us to test for now~. EDIT: We got CSS to work too! For every component under test, you have to check if the component is being used in the browser or the server. If it is being run in the browser, "require" the CSS files. It if is being run in the server. do not "require" the CSS files.
*Thread Reply:* hm. You should be able to get around that by leveraging babel runtime or modifying where you’re introducing babel to the project. That would enable you to keep the code consistent throughout
*Thread Reply:* Hi @Andy Nguyen I have the same problem and I've install the packages that you mentioned, but still no result. Still getting the "import React from 'react'" error. I've tried to import all things with require and it works, but then it doesn't recognize the JSX syntax, because I'm using shallow from enzyme. Do you have any idea how I can solve this problem. Thanks
*Thread Reply:* We are also using enzyme, so that shouldn’t be the issue.
*Thread Reply:* Can you show me some example, or article how to setup all together and use it, I will be very thankful
*Thread Reply:* I’d just look at the babel.io docs. They’re pretty thorough re: setup and config docs.
*Thread Reply:* @TVlasev I made a tutorial and example project of how to configure Cucumber, Enzyme, and Create React App. Hopefully having this example project and tutorial will encourage more people to use Cucumber with React. Let me know, if this helps you https://github.com/NguyenAndrew/Enzyme-Cucumber-React
*Thread Reply:* @Andy Nguyen Great repository, looks really good, I'll try it out and let you know if helps, thank you for the effort
*Thread Reply:* @Andy Nguyen It's working, it's great repository, I'll spread the word, hope more people will use it, thank you! Just one more question: If we have a normal tests with jest and enzyme and we want to run them too, i guess i can just add "react-scripts test", like that: "test": " react-scripts test && npm run babel-src && npm run babel-test && npm run cucumber-test" ?
*Thread Reply:* @TVlasev Yes, that should work as the create react app was not ejected.
*Thread Reply:* @Andy Nguyen Just like suggestion in FAQ / Troubleshooting section you can include what to do if css files throws an error and how and where to include them.
*Thread Reply:* @TVlasev Ah thank you for the suggestion. I am hesitant on adding the Jest react-scripts question to the FAQ, because it is more of a “How do I use npm?” question rather than “How can I integrate Cucumber, Enzyme, and Create React App?”. Another reason: Cucumber plays very with many different testing frameworks, so I am trying to keep the tutorial focused. Maybe I will make an other questions page?
*Thread Reply:* @Andy Nguyen maybe i did't express myself well, sry for the bad english 😄 If we use a css file in a component when we run npm test, it gives this error: Unexpected token . Copy\transpiled\style\style.css:1 (function (exports, require, module, _filename, _dirname) { .search-bar { I think it's related to the subject, because if we use a imported css file in the component we can't test the component because the error. Node doesn't understand css syntax. Correct me here if I'm wrong
*Thread Reply:* @TVlasev That question is in the FAQ of the repo: "I have a Syntax error: (function (exports, require, module, _filename, _dirname) { .App {
SyntaxError: Unexpected token ."
*Thread Reply:* You should be able to ctrl+f that question, as example code is provided below the answer to solve that issue. Let me know, if you still have problems.
*Thread Reply:* @Andy Nguyen ohhh, I'm sorry, i saw it. But still gives me the error when I use a css selector on JSX element. In src/ folder I have a style/ folder with style.css file in it. And I do the import with "import: ../../transpiled/style/style.css" in stepdefs.js file but still gives the same error.
*Thread Reply:* @TVlasev I am confused on this part: "And I do the import with "import: ../../transpiled/style/style.css" in stepdefs.js file" Can you clarify on what functionality you are testing when you import the CSS into your stepdefs? From my experience, you import/require the CSS into the corresponding react component (checking if the dom exists like you read in the FAQ), and the stepdefs.js would import the react component,
*Thread Reply:* @Andy Nguyen Now i get it.. I've deleted the canUseDom func... 😄 now everything is ok.. sorry for this. Thank you again for your time
*Thread Reply:* @TVlasev 😄 Alright. Interesting that deleting the canUseDom functionality solved your problem. You are welcome
*Thread Reply:* @Andy Nguyen no, no I've deleted it by mistake, after I added it back everything was OK 😄 Sry again for the english 😄
*Thread Reply:* @TVlasev Good to know. Glad you solved the problem!
*Thread Reply:* Cat's advice led me to an awesome discovery, which should be beneficial to all React Cucumber developers (Unit Tests with no drawbacks, no rearranging of the step_definitions folder, and no transpiled folders). ~I opened an enhancement ticket on the tutorial project~ Enhancements have been implemented!
*Thread Reply:* @TVlasev I have implemented major improvements in the tutorial that improves the developer experience when using Cucumber with React. I would recommend updating your project to use them.
Hi peeps,
Wonder if anyone could help with the following.
When my cucumber script runs and it doesn't find any tests for the tag that I am using it returns a SUCCESS result, which could potentially result to false positives. How can I make it fail for such a scenario?
16:44:50 + node ./node_modules/cucumber/bin/cucumber-js ./test/features/ --format ./node_modules/cucumber-pretty --strict -t @testtag
16:44:51 0 scenarios
16:44:51 0 steps
16:44:51 0m00.000s
16:44:51 Finished: SUCCESS
@Kostas I believe I’ve seen similar problems using ant when invoking cucumber for a feature file that does not exist
@Cat am new to cucumber js. Is it possible can please share some samples project with google navigation and click search operation with selenium web driver ?
*Thread Reply:* I don’t have any samples off hand. what in particular are you having trouble with? the cucumber setup docs are pretty straightforward 🙂
Hello Cuckes!
Is there beforeAll and AfterAll hook available? If so how do i invoke this?
This is my code
const BeforeAll = require('cucumber')
BeforeAll(async () => {
//steps
})
*Thread Reply:* I’m mid-meeting so can’t look it up rn, but I believe it’s just Before and BeforeEach
*Thread Reply:* Thank you for taking time to reply. 🙂
is there a better way/strategy to do a "setup" before any scenario runs?
*Thread Reply:* Hm. I would say it depends on precisely what you’re needing to do.
*Thread Reply:* @Cat so dumb of me..I put all my steps for data setup in before hook. This runs before any of the scenarios runs. not sure if this is the most efficient.
I am not sure if it runs before every single scenario
*Thread Reply:* I do know if its a tagged hook, it will only run when called in a feature file. a general Before hook i am guessing will run before every scenario. Testing this theory..
*Thread Reply:* hm. So, ymmv because how one automates one piece of software may vary wildly from the next, but for me, I find it helps to do data setup as part of the specific feature or scenario - usually in the Background steps. Now, there are some things that are more generic (for example: if you want to log in via API and get cookies - that’s likely something that applies to a ton of your tests and you can just do that as a before hook and pass the cookie values through there)
*Thread Reply:* But again, that is going to vary greatly depending on the how and why 🙂
*Thread Reply:* there are definitely cases where handling the data setup is completely legit in the Before hook
*Thread Reply:* or it may be that some of the data setup should be in the Before hook, but other pieces need to be done only before tests with specific tags, etc
*Thread Reply:* That's exactly what i intended to do with the data setup(maybe data setup is not the right word here). There are some reference data, that are constant that are needed as a pre-req, i am using API calls to prepopulate them. Ther are also other data setup that are specific to a feature file which are done via background. And lastly there are ones which need some, random data to be created, these are done with tagged hooks.
i am getting an error Unhandled rejection TypeError: BeforeAll is not a function
Hello people 🙂 I have a question regarding cucumber.js. I hope this is the right place to ask it 😛
So, Is it possible to get currently executed test tag in beforeScenario function? If it is possible how to do it? 😄
Here is the link on stackoverflow where I asked the question https://stackoverflow.com/questions/53729101/cucumber-how-to-get-scenario-tag-that-is-currently-being-executed
but with no luck yet for answers 😁
*Thread Reply:* Hm, are you using straight cucumber-js or are you using wdio-cucumber?
*Thread Reply:* Hm. that’s quite an old version. 🤔 That may be part of why you’re having difficulty. I want to say a few things have changed about how tags are fed in as far as where they’re available to reference, so I wouldn’t easily be able to answer that straight off
*Thread Reply:* tbh, I’d start first with just playing around with console.log to see if you can just get it to log the tags and go from there.
*Thread Reply:* yeah, it's like that on the project I'm currently working on and upgrading the version is not an option at the moment 😞
*Thread Reply:* I can get the scenario tags by this:
beforeScenario: function (scenario) {
tags = scenario.getTags();
tags.forEach(function (scenarioTagItem) { ... });
}
*Thread Reply:* but what I can't figure out is how to address/catch the tag of the test that is currently being under execution.
*Thread Reply:* Hm. That I probably can’t help much with until I have some time to play with a test project
*Thread Reply:* So for example, I have scenario with multiple tags, but conf.js file only running certain tag @registration and I want to catch that this scenario is being run under that tag => I know what are all tags which with scenario is tagged, but how do I catch the active one
*Thread Reply:* Hm. Since it’s an older version and I’m just guessing here, I don’t want to point you in the wrong direction, but what happens when you try to reference something along the lines of this.scenario? Are you able to access tags that way?
*Thread Reply:* when I do <a href="http://logger.info">logger.info</a>("XXX scenario " + scenario.toString()); I get info: XXX scenario [object Object]
*Thread Reply:* when I do <a href="http://logger.info">logger.info</a>("XXX scenario " + JSON.stringify(scenario)); I get info: XXX scenario {}
*Thread Reply:* I have in conf.js file this among some other things:
*Thread Reply:* before: function () { const chai = require('chai'); global.expect = chai.expect; global.should = chai.should(); global.logger = require('winston'); global.i18n = i18n;
browser.setViewportSize({width: 1200, height: 1057})
}
*Thread Reply:* so I guess it is using winston for logging purposes
*Thread Reply:* yes, sounds like - try just console.log instead and lmk what you get
*Thread Reply:* console.log("XXX scenario " + JSON.stringify(scenario)); => Still the same XXX scenario {} 😞
*Thread Reply:* Hm. that is odd. I’m afraid I’m not gonna be much help on this until I have some time to poke around with that version
*Thread Reply:* getting stuck with older versions is always difficult 🙂 to attempt to point you in the right direction - I’d keep playing around with that object and see if there’s anyway to successfully destructure it and get more info on what’s (supposed to be) in it
*Thread Reply:* I managed to debug it and searched with offered options that were there, but I think none of it will help me
*Thread Reply:* What I really need is a a way to get the tags from configuration file main.conf.js that are set in the attribute:
cucumberOpts: {
tags: ['@registration', '~@WIP']
}
in function beforeScenario?
*Thread Reply:* not the ones that are actually on the scenario itself
*Thread Reply:* and all of these are actually getting those tag that are on actual scenarios
*Thread Reply:* I did it :nyanparrot: it was stupid => just called this.cucumberOpts.tags because it was in the same file and build my logic further on that
*Thread Reply:* but thank you again for you time and help, I really appreciate it 🤗
*Thread Reply:* Just curious - what’s the need for retrieving tags at run-time ?
*Thread Reply:* I have multiple profiles in wdio for different purposes (in this specific case countries) and I needed logic to know for which country did tests run @fr , @uk and so on @Andrew Peacock
Hi everyone, is anyone here able to review a small JavaScript example to add to the docs? https://github.com/cucumber/docs.cucumber.io/pull/287
*Thread Reply:* I am not a "reviewer", but I did take a look and made some comments.
*Thread Reply:* You're a reviewer now @Andy Nguyen :) Thanks!
*Thread Reply:* Please stop by the docs anytime to improve the javascript side of things ;)
How are formatters used in cucumber-js? (specifically how do I specify junit?)
@Gem there are a few different ways to do it, iirc (been a few months since I set up the formatters on the newer project)
Ended up with cucumber-js --format=json | cucumber-junit > junit.xml
Anyone who's familiar with bash, piping, and whatnot, able to modify my command above so that the exit code from cucumber is still returned to the terminal running it? Right now, if anything fails, the code isn't returned so CircleCI doesn't think anything's wrong.
*Thread Reply:* ```export default async function run () { const cucumberCli = new cucumber.Cli({ argv: execArgs, cwd: process.cwd(), stdout: process.stdout });
var cliRun = await cucumberCli.run();
process.exit(cliRun.success ? 0 : 1);
}```
*Thread Reply:* Since the junit formatter requires piping the output the exit code being returned to Circle was for formatter which always passed, so Circle thought the Cukes were always passing, too
I have not solved this problem before, but maybe this will help @Gem https://stackoverflow.com/questions/1221833/pipe-output-and-capture-exit-status-in-bash
No problem js! Let me know what you end up using, as my team might encounter the same problem in the near future.
*Thread Reply:* I couldn't get it working and didn't want did want to bash my head against it so decided to switch to Ruby. 😛
Hey all, I was just wondering what the best practice is sharing variables across multiple steps (in the same spec file). E.g In one step I call a click() method on some page object, which returns another page object (if the operation is successful). Then I want to access this newly instantiated object in another step to call some other methods on it.
I looked into the World object on the docs but I wasn't able to figure out how to use it
To clarify, the second step would be in the same test scenario as the first one
@Andrew If you want to share variables between steps, store the variable in 'this'. For example, Given('...' function() { this.variableThatYouNeedToShareBetweenSteps = ... }); When('...' function() { this.variableThatYouNeedToShareBetweenSteps.doDomethingWithThisVariableInAnotherStep(); });
Definitely go through this tutorial https://docs.cucumber.io/guides/10-minute-tutorial/, if you haven't touched Cucumber.js before
Thanks for this ! In terms of 'best practice', which of the two following methods do you think is better? Say I have a 'Main Modal', that has a button that will open up a 'Sub Modal'. Currently, I have created ES6 class based page objects for both modals and I am storing a reference to the Sub Modal in the Main Modal like so
// using typescript
class MainModal {
// Sub Modal page object
public subModal: SubModal
// button has been abstracted into a 'Button' page object to encapsulate its functionality
public button: Button
constructor() {
this.subModal = new SubModal();
}
public openSubModal(): Promise<void> {
//click is a custom method in Button class
return await this.button.click();
}
// rest ommitted
}
So in my spec file I have something like this
const mainModal = new MainModal();
When("the user opens the sub modal", async () => {
await mainModal.openSubModal();
});
When("the user does something in the submodal", async () => {
await mainModal.subModal.doSomething();
});
The problem with this is that I end up with lots of nested page objects so method calls end up being extremely long.
Would it be better to make the openModal() return the SubModal page object like this, save it into the 'World' object, and then access it in the next step.
Are there any potential problems to watch out for when introducing dependencies between steps?
When("the user opens the sub modal", async () => {
this.subModal = await mainModal.openModal();
});
When("the user does something in the submodal", async () => {
await this.subModal.doSomething();
});
First, look at this page to see how to use promises with Cucumber.js https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/hooks.md. Notice that instead of doing async/await, you return the promise you want to be resolved. This guarantees the promise has resolved in each step, before moving onto the next step. If you have multiple promises you can return Promise.all([promise1, promise2, ...]) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
It might be worth testing out the modals into two scenarios. The examples you presented tightly couples the "opening of a modal" and "doing something inside of a (sub)modal". Here is a possible refactor, which should make the scenarios cleaner. Feature: Accomplish some cool task 1. Scenario: Main Modal opens up Sub Modal on button click 2. Scenario: Sub Modal does stuff based on user interaction
Thanks for the reference, I will take a look into the page about using promises but I have been using async/await so far and all the asynchronous operations have been handled correctly (i.e all of protractor's functions). Regarding the second point- even if you split it into two scenarios, wouldn't you still need to open the sub modal from the main modal before you can have the sub modal do stuff 'based on user interaction' ? In this case, your feature will look something like
When the user opens the submodal
And the sub modal does stuff based on user interaction
Essentially I guess my question here is where do you instantiate the Sub Modal page object ?
Opening the sub modal from the main modal doesn't have to be necessary. You can split up the tests like this Given a modal, when a button is clicked in the modal, then a sub modal is displayed Given a sub modal, when interacted on a certain way, then this stuff is visible It depends if your code is structured in a way where you can create a sub modal without needing its parent modal.
Technically they are instantiated in two places. The first scenario being this.submodal = mainModal.clickButton() //Located in your when statement The second scenario, this.submodal = **require/new subModal(..)/etc.** //Located in your given statement whatever you use to instantiate your sub modal.
Unfortunately I can only access the sub modal by clicking on some button in the main modal. In my test case I have already done what you mentioned above ( splitting it into two scenarios). In the first scenario I open the sub modal via the main modal and verify that all UI elements are present. In the second scenario I open the sub modal via the main modal, perform some actions in the sub modal, then verify the correct behaviour is performed.
I also realised I had some errors in the initial code example I sent (I have updated it now)
In the example above, I am access the doSomething() method in the SubModal page object via the MainModal (mainModal.subModal.doSomething()). Is there any glaring problems doing it like this?
(sub modal page object is instantiated in the constructor of the main modal)
The one limitation I am facing right now with this method is that the complexity of the angular website I am testing means there are lots of nested page objects. This makes method calls overly long e.g somePageObject.anotherPageObject._.doSomething().
But as I am with dealing with so many different page objects, I'm not too sure where I should be instantiating each one, which is why I am using this 'nested' structure where the creation of these objects aren't done explicitly in the spec file
For something like this I would have a MainPage page object, that holds references to the LeftPanel, MainPanel and RightPanel page objects. And then because the MainPanel has a button that opens a pop up modal, I have a reference to the PopUpModal page object in the MainPanel
So calling a method in the PopUpModal page object would look like mainPage.mainPanel.popUpModal.doSomething()
// main-page.page.ts
class MainPage {
public leftPanel: LeftPanel
public mainPanel: MainPanel
public rightPanel: RightPanel
constructor() {
this.leftPanel = new LeftPanel();
this.mainPanel = new MainPanel();
this.rightPanel = new RightPanel();
}
// rest ommitted
}
// main-panel.page.ts
class MainPanel {
public popUpModal: PopUpModal;
constructor() {
this.popUpModal = new PopUpModal();
}
}
In reality, the page objects would have names related more closely to the domain (instead of MainPanel, LeftPanel etc), but I wanted to give a generic example to illustrate my idea
There doesn’t seem to be any glaring problems, looking at the example code you provided. It seems like your modals are in a tree shape, similar to how React uses a component tree like structure. When you are constructing the MainPanel PO in your tests, do you need to first instantiate MainPage PO? Are you proxyquiring modules that aren’t being looked at in test?
Also, looked into async/await. Async makes a function return a promise, so that is why that code snippet works. Choose what you prefer / makes the code cleaner.
So, in my spec file I only instantiate a single MainPage PO (this PO then instantiates all left, right and main panel PO's in its constructor). It looks something like this
// inside some-spec-file.ts
const mainPage = new MainPage();
When("the user opens the pop up modal", async () => {
await mainPage.mainPanel.openPopUp();
}):
Then("the user does something in the pop up modal", async () => {
// PopUpModal is created in the constructor of MainPanel which is created
// in the constructor of MainPage
await mainPage.mainPanel.popUpModal.doSomething();
});
This line of code const mainpage = new MainPage()- its not saved in the World object so does it only get created once throughout the running of the entire test suite?
Also, you could imagine these method calls getting longer and longer when the nested tree structure becomes more complex- which is why I am trying to find a better way to do things
Here is a way of you can split up your tests. As you can see in this example at the bottom, to achieve the ability of not having extremely long nested calls, you need to be able to instantiate the components/modals separately. This layout makes the code cleaner, and achieves a strong test suite. @Andrew
Are you suggesting that the openPopUp() method in the MainPanel PO (which sends a click command to the button) returns a PopUpModal PO ?
It doesn't have to (just a single suggestion, out of different implementations), but MainPanel does do some delegation of some action to another component. Is this interpretation correct? You can verify that the MainPanel does the action it needs to do for unit testing, and you can verify that PopUp Modals does what it needs to do as well in other unit tests. You can then write an end to end test to see if the components work together to achieve expected behavior, solving the nested calls problem. I also have another question @Andrew. For these examples, were the tests written before the code was created (or is this an existing code base)?
Thanks @Andy Nguyen, I'll give that a shot. Also, yes this is an existing code base so I am writing the tests after- originally I was focusing too much on the UI when writing tests so I'm trying to have a perspective shift now.
Also, I currently have X groups of tests, and for each group I would like to create a custom World object. Do you know how to achieve this? More specifically, I would like to be able to define an interface in TypeScript for the variables that would be stored in each world object. I saw this article https://sylvain.pontoreau.com/2018/04/30/typescript-cucumber-getting-started/, which describes how to add types to the default World object (so you are able to get intellisense suggestions) but I was wondering if this is possible for custom Worlds.
*Thread Reply:* @Andrew From my understanding Cucumber.js doesn't allow you to share state between different scenarios (and may be an anti-pattern? I need confirmation on this statement). You can use the before/after hooks with tagging to setup and tear down state for each scenario in a group https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/hooks.md
*Thread Reply:* @Andrew I have raised this issue which would be a great feature that could allow the configuration of multiple world classes based on test type. Feel free to chime in what any other suggestions. Another way you could do it is by having different support folders declared in your cucumber profile but I'd like to stay away from separation by folder and instead let tags drive world configuration. https://github.com/cucumber/cucumber-js/issues/1174
hello. I'm trying to integrate cucumber.js into my existing project, and am having a bit of difficulty. I'm getting the example test I made to run when I have a folder in my root directory called features/, but I'd like to put this folder inside my tests/cucumber/ folders. Could anyone help me out with this?
*Thread Reply:* How are you passing it into Cucumber? (cli or cuke options - just need to see how you’re passing it in)
*Thread Reply:* Hi cat, I used the ./node_modules/.bin/cucumber-js command
*Thread Reply:* all works well when the features folder is in the root directory, but I can't seem to find any way to run the tests if the folder is elsewhere
*Thread Reply:* Right. Cucumber has to be told where to read files from (if they aren’t in default locations). How are you passing that in?
*Thread Reply:* Not sure where i'd be passing that in. Sorry I'm brand new to cucumber
*Thread Reply:* I did try cucumber.js tests/cucumber/features/example.feature as well as --require but neither worked
*Thread Reply:* Try node_modules/cucumber/bin/cucumber-js test/features You shouldn't need require
*Thread Reply:* I made a full stack Cucumber React boilerplate last night with a feature folders in a test directory (instead of root). If the previous advice doesn't work, taking a look at this repo should help you run feature folders in directories outside of test, https://github.com/NguyenAndrew/careen.
*Thread Reply:* Hi, it's cukebot again. "Doesn't work" is rather vague. What are you seeing and what had you expected to see?
*Thread Reply:* Thanks, Andy. I did try that and i'm getting 'no such file or directory'
*Thread Reply:* I restarted my terminal, and now i'm no longer getting 'no such file or directory' but it thinks my feature is empty:
0 scenarios
0 steps
0m00.000s
*Thread Reply:* In your folder structure, can you indicate for me where your feature files and step definition files are located?
*Thread Reply:* Sure. here's my folder structure right now:
project
|-- tests
|-- cucumber
|-- features
| --example.feature
| --step_definitions
|-- stepdefs.js
*Thread Reply:* So instead of doing node_modules/cucumber/bin/cucumber-js test/features Try doing the following node_modules/cucumber/bin/cucumber-js tests/cucumber/features
*Thread Reply:* that worked perfectly. thank you both for your help I really appreciate it
*Thread Reply:* btw Andy that boilerplate is awesome! i miss using react 😢
*Thread Reply:* Thanks for the compliments. Hope you can jump back to the React world soon.
Sorry, I may have misphrased my question. Say I have Scenario's A1,A,2,B1,B2,C1,C2. All I want is that A1 and A2 use CustomWorldA (this world can and still should be refreshed after each scenario -> so A1 and A1 receive fresh world instances), and B1 and B2 to use CustomWorldB and so forth.
I would like to define some types for the variables that will be saved in each custom world
I think I just read your question too fast. I would start with just using different variable names to define the type of your variables in your world for MVP (i.e. single world for all of your scenarios). I am not sure if you can specify which "typed" world to use for individual/groups of scenarios.
You can specify world by passing it via CLI. For what’s being described, however, I’d just use before hooks and tagging 🤷♀️:skintone2:
Hooks, steps, and world all share ‘this’ so for specific variables that should be shared across certain tests, it’s a bit easier to go by tagging and hooks when you need to debug.
Hello all,
I’m using protractor-cucumber-framework and would like to increase the cucumber global timeout.
It appears that increasing the protractor global timeout is not working. I believe the cucumber global timeout is the one that needs to be updated.
Anyone knows the proper way to increase the global cucumber timeout globally in this framework?
*Thread Reply:* You can set the timeout globally with: ```var {setDefaultTimeout} = require('cucumber');
setDefaultTimeout(60 ** 1000);``` This link show you how to set the timeout both locally and globally https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/timeouts.md
*Thread Reply:* Thanks Andy, I’m using protractor.conf.js to run my tests.
I’m not sure where this will fit in this file. I get an error when I set the timeout in it.
var {setDefaultTimeout} = require('cucumber');
setDefaultTimeout(60 ** 1000);
error:
setDefaultTimeout(60 ** 1000);
^^
SyntaxError: Unexpected number
*Thread Reply:* iirc (been a while since i used protractor), you can just pass it into cucumberOptions in the conf
*Thread Reply:* This is what I currently have:
cucumberOpts: {
require: ["features/step_definitions/**", "support/hooks.js"],
format: "json:./reports/cucumber_report.json",
tags: ['~@todo', '@regression'],
},
what it the proper way to add setDefaultTimeout(60 ** 1000) to it?
*Thread Reply:* hm. try plugging in defaultTimeout: (yourTimeout) or just timeout: (yourTimeout) in that config.
*Thread Reply:* I handle the setDefaultTimeout bit in my world setup code so how I pass it in is a bit different than what you’re doing. However, iirc, it should be passed in through options.timeout if it’s coming through as cucumberOpts
*Thread Reply:* I tried plugging in defaultTimeout and also timeout but none worked.
*Thread Reply:* hm. I’d suggest having a look at the protractor-cucumber-framework code to see if it exposes cucumber timeouts and if perhaps it has a different naming convention?
*Thread Reply:* I created a new file env.js and added
module.exports = function() {
this.setDefaultTimeout(10 ** 1000);
};
then added this to protractor.conf.js under cucumberOpts
require: ["features/step_definitions/**", "support/hooks.js", "support/env.js"],
*Thread Reply:* There has to be a simpler solution but this works for now. Thanks @Cat @Andy Nguyen!
*Thread Reply:* @Omar In your protractor config file, there is an onPrepare method available to you. You should be able to set the timeout in there.
*Thread Reply:* Let me know if it doesn't work and I can dig a little more but i suspect it will
*Thread Reply:* Hi, it's cukebot again. "Doesn't work" is rather vague. What are you seeing and what had you expected to see?
Hi, it's cukebot again. "Doesn't work" is rather vague. What are you seeing and what had you expected to see?
Hi everyone, I am new to cucumber and javascript and have a quick question. I have a test where I do some actions and in the end, would like to verify if certain text is visible on the page. I would like my function to be some like “isTextVisible”. In selenium java, I would do something like below
if(driver.getPageSource().contains("Text to check")){
System.out.println("Text is present");
}else{
System.out.println("Text is absent");
I am trying to do something similar but JS does not identify getPageSource as a function and throws the error TypeError: driver.getPageSource(...).contains is not a function
i would appreciate any help on how to make this work. PS: I read about node js Assertions and I thought those would not serve my purpose in this case unless I am wrong.
*Thread Reply:* This seems more like a selenium webdriver question than a cucumber question. However, I did look into this question for you. https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/ie_exports_Driver.html#getPageSource returns a promise to a string. If you don't know promises, callbacks, or how asynchronous code works in JavaScript definitely do some research before continuing past this code. In any case do driver.getPageSource().then((source) => { if source.contains("Text to check") {...} else {...} });
*Thread Reply:* Thank you so much @Andy Nguyen!. That worked with a minor change. .contains does not work in chrome. So, I had to use source.indexof https://stackoverflow.com/questions/19589465/why-javascript-contains-property-is-not-working-in-chrome-browser. Anyways, thanks again 🙂
Hi everybody, can you help me with this issue? I'm trying to change the final report of cucumber, because I don't want to show messages like 'timeout'. I want to change to 'element not found' or something like that. How can I do that?
I used try catch, but on catch I put 'console.log('error message', error). I would like to change the message of timeouts that came together.
then you’d just throw a new error with whatever specific text you’re wanting - although if you’re timing out, you may want to evaluate where the timeout is coming from - your driver or cucumber (or underlying helpers)
when I use this code, I receive this: × failed Error: function timed out, ensure the promise resolves within 20000 milliseconds at Timeout.time.default.setTimeout [as _onTimeout] (\nodemodules\cucumber\lib\usercoderunner.js:81:20) at listOnTimeout (timers.js:324:15) at processTimers (timers.js:268:5)
I'm trying to change the message of timeout to another, like you put there "Unable to find element"
This points to a different problem, the problem being that your default timeout for cucumber is less than your selenium timeout
const selector = '#login-button';
try {
await this.document.waitForSelector(selector);
} catch (error) {
throw new Error('Unable to find element');
}
I'm trying to do that. But i would like to receive the message of 'Unable to find element', not the timeout default error
Right - the issue is that your underlying function is taking longer than what you’ve set cucumber to timeout at
await this.document.waitForSelector(selector);
Cucumber is timing out here ^ not selenium
You have a couple of choices
Since many cucumber step definitions may require the execution of multiple driver async functions in a single stepDef, i strongly recommend setting the default cuke timeout to be a bit higher than your default driver setting
*Thread Reply:* I agree with @Cat a custom timeout on each call is a bad choice. My opinion is to increase the cucumber timeout.
*Thread Reply:* The problem isn't find the element. I want to handle errors when it happens. I'm trying to nominate my errors to do a better log for the UI Tests.
*Thread Reply:* Agreed the problem isn't finding the element because you actually don't know if it's being found or not because cucumber keeps timing out first.
*Thread Reply:* Yes. My tests are working fine. But I need to do a error handling because I want to make the code more maintable for everyone.
*Thread Reply:* ^^ Raymond is correct. The issue is that you’re trying to solve it in the wrong place - you need to give cucumber a longer timespan than the underlying driver functions in your step definition. If you run a stepdef with cucumber and set timeout to 2k, but your driver is set to 3k, cucumber gets the error. Cucumber has already failed your test before driver can finish attempting to resolve - this is exacerbated further if your stepDef is a helper function that waits for multiple driver functions to resolve.
*Thread Reply:* Yes. And you cannot capture an error in your driver if you aren’t waiting for it to fail
*Thread Reply:* You fail in cucumber right now before giving driver time to fail
*Thread Reply:* You will not capture an error at driver level if you consistently timeout in cucumber (because that wraps your driver step)
*Thread Reply:* const selector = '#login-botao1';
const promise = new Promise((resolve, reject) => {
setTimeout(async () => {
await this.document.waitForSelector(selector);
resolve();
}, 20000);
reject();
});
try {
await promise;
} catch (error) {
throw new Error('Unable to find element');
}
*Thread Reply:* I change the code for that and receive this message: Error: Unable to find element
*Thread Reply:* But the problem is that always got reject...
*Thread Reply:* Looks to me like the same problem with the only difference being you now have control of the problem
*Thread Reply:* Have you confirmed waitForSelector works. Also what error is being received into the catch? I presume the timeout error again right?
*Thread Reply:* × failed Error: Unable to find element at Login.<anonymous> (\tests\acceptance\pages\login.ts:33:15) at step (\nodemodules\tslib\tslib.js:133:27) at Object.throw (\nodemodules\tslib\tslib.js:114:57) at rejected (\node_modules\tslib\tslib.js:105:69)
*Thread Reply:* I would like to have this error on my log and I got this
*Thread Reply:* Can you console log the error the catch is getting before you throw your custom error
*Thread Reply:* Have you confirmed your waitForSelector method actually works?
*Thread Reply:* Okay can you console print the error entering in the catch
*Thread Reply:* That doesn't sound right You did console.log(error) at the start of the catch right?
*Thread Reply:* I resolved the problem using promise (resolve, reject). I remove some calls in the function and worked fine. Thanks for the help! 😁
*Thread Reply:* Hi! "Guys" is easily replaced with the more gender-neutral "Folks", "All" or "Foolish mortals". We'd appreciate if you tried to use that. Thanks!
how can I add a custom cucumber timeout? Surround the waitForSelector with a timeout and throw the exception there?
@channel I have setup a new channel <#CG5736HU5|cucumber-js-git> which integrates slack with the cucumber-js github repo
For more info on what that will look like feel free to 1. Join 2. Take a look at https://slack.github.com/
<#C612KCP1P|committers-js> might be a better channel to announce this in, too. 😛
What's the command do you use after a click? waitFor? waitForNavigation?
*Thread Reply:* That’s going to vary quite a bit based on which driver you’re using. It’s also not really a cuke question 😉
*Thread Reply:* Like @Cat says we are going to need some more context. Also that is a selenium question and can be asked in #selenium
Hi I'm new to cucumber(JS), and I'm looking for examples of dependency injection... my main goal would be to get rid of this.something (especially when this refers to an object located in another file...) in order to access to shared instances in handling functions... do you have some ideas ?
example :
import {TableDefinition} from "cucumber"
import { binding, given, before } from "cucumber-tsflow"
import {Customer} from "../../src/domain/customer"
import {InMemoryCustomerRepo} from "../../src/adapters/inMemoryCustomerRepo"
import {CustomerRepo} from "../../src/domain/interfaces"
class CustomerConfig {
public customerRepo: CustomerRepo;
public constructor() {
this.customerRepo = new InMemoryCustomerRepo()
}
}
@binding([CustomerConfig])
class CustomerSteps {
private customerRepo: CustomerRepo;
@given(/^des clients existent:$/)
private clients(dataTable: TableDefinition): string | void | Error {
dataTable.rows().map((r) => {
this.customerRepo.Create(new Customer(r[0], r[1], r[2]))
})
return "pending"
}
public constructor(config: CustomerConfig){
this.customerRepo = config.customerRepo
}
}
export = CustomerSteps
My main questions are "What should I do to make the browserstack-cucumber-js repo work with the newest version of cucumber, seleniumwe driver and cucumber-assert?"
And
"Is it worth trying or can you point me in the direction of an up-to-date documentation explaining how to use cucumber-js with browserstack?"
*Thread Reply:* If I’m not misremembering, you can just pass in your browserstack config via your webdriver config (webdriverio has some good examples). It’s going to vary some based on what you’re using, but isn’t so much a cucumber question.
*Thread Reply:* The Browsertstack repo uses the selenium webdriver and I guess the hooks.js file to configure it to use browserstack. But it only works with the old versions of cucumber and selenium the repo uses. So you think I can easily build it myself with new versions? Do you maybe have a good video or documentation on that
*Thread Reply:* webdriverio is a wrapper for selenium webdriver + appium. whether you’re using selenium webdriver or webdriverio, you should be able to pass the Browserstack parameters through the config. BrowserStack has docs here: https://www.browserstack.com/automate/node
@Maxim I'm not as familiar with the js version, but someone who is may be able to get back to you, just be patient. 🙂
Hi, I am trying to enter a text in to a field with no input tag. It has only label tag. Using selenium cucumber js. Below is my step definition
this.Then(/^I enter "(.**)" into the First name field$/, text => {
var firstName = by.css("label[for='firstname']");
shared.helpers.click(firstName);
return shared.helpers.enterTextInField(text, firstName);
})
I added the extra line with click because I was getting following error
however, that did not fix it. I tried several options and kind of fed up. Any help would be appreciated on how I can enter the text successfully in to the fields 🙏
*Thread Reply:* It’s an issue with how you’re interacting with the DOM, hence the selector error. It’s pretty much entirely unrelated to cucumber. 🤷♀️:skintone2: The selector you’re using cant interact with the dom in the way you’re attempting to. The most likely cause is that you’re attempting to set the input value in the wrong place. If you’re still struggling with it, you may want to check out #selenium or seleniumhq.slack
*Thread Reply:* Can you open up the divs as it looks like First name is a header and not an input field
Hey @Madhulika have you tried looking up selector errors with webdriver as that's what's producing the error
cannot focus element sounds like your selector isn't able to find the element.
I think the selector you're trying should work but might not be perhaps because it looks like there's no actual input bound to it?
*Thread Reply:* Hi @Gem: yeah, the problem is because there is no input tag. I will see if there are some workarounds. thank you.
Everything is fine until I try to define and use a profile instead of having the full command line in my package.json
But if I add a cucumber.js file in the root directory and execute cucumber-js I get the following error :
When I add the cucumber.js file, it clashes with the cucumber library when I do import { After } from 'cucumber;
@Akaan Could you share what config changes you had to make with us here so that in the future it could be used to help others?
Sure ! My tsconfig.jsonhad "baseUrl": "." so that import { After } from 'cucumber'would try to import from the cucumber.jsfile at the root of the project instead of importing it from the node module.
Hi everyone, what is the best way to do UI and API testing using Cucumber.js. I have a usecase where a scenario starts with some UI steps and then I need to hit the Gmail API to fetch a link from an email (that was sent from the UI test). After I get the link I need to go to it and do some more UI actions. Should I separate the UI and API tests in to separate directories?
@Madhulika are the UI and API steps part of the same test, or are they separate tests for different features? I'd group tests/scenarios according to functionality and features and might group step definitions related to which part of the domain they deal with. A division with type of step definitions (UI, API, mock) might also make sense.
thanks @mlvandijk. The UI and API steps are part of the same test i.e same scenario and I have multiple scenarios like that.
In that case I might personally group them into UI step defs and API step defs. But grouping by domain would also work.
Hi everyone, can cucumberjs be used without a broswer to test at a lower level like jasmine is being used?
*Thread Reply:* I can try put together an example this weekend if I get time but the cucumberjs docs should be all you need https://github.com/cucumber/cucumber-js/tree/master/docs
*Thread Reply:* So at a lower level chai is the runner? https://github.com/cucumber/cucumber-js/blob/master/docs/nodejs_example.md
*Thread Reply:* Also when your using it a a lower level what are you using mocking?
*Thread Reply:* No but it doesn't matter. Cucumber has no dependency on what it is testing. Cucumber is simply a framework to trigger some code to run
Hello< I am scratching my head to find a way to connect cucumber-selenium-js to a selenium grid hub. I am sure there must be a config variable to put the hub address but I am not finding it. Can someone help? Please🙏
*Thread Reply:* I haven’t worked with that particular implementation, but I’d assume that you can probably just use selenium standalone, which can get your grid sorted out. https://www.npmjs.com/package/selenium-standalone
is there anyway to re-run failed scenarios in cucumberJS without having to define a custom reporter using webdriverIO?
*Thread Reply:* https://cucumberbdd.slack.com/archives/C60TKS3SL/p1551200783073000?thread_ts=1551164882.031900&cid=C60TKS3SL
*Thread Reply:* Ah I see @Raymond, if you don't mind would you happen to have an example I can maybe look at?
*Thread Reply:* @Leo
--format rerun:@rerun.txtHas anybody got any tips on running pre-commit hooks with cucumber? I'm thinking of implementing husky that will have a pre-commit hook to run my cucumber tests. The only additional complexity is that I don't want a failure if tests are not 100%. I'd like to have an acceptable pass rate of say 95%( 5% known bugs etc). My initial thoughts is husky could kick off a bash script which would run the tests gather the results and then do a compare on the acceptable pass rate value. The idea is that the pass rate should never fall when a dev is checking in code.
The other option is I could have only blockers in the pre-commit hook, which is an option but I'd also like to explore the option of a full regression run with an acceptable pass rate.
does anyone also have this problem where it takes a really long time to generate an allure report ?
Hey all, just getting started with cucumber JS and loving it so far. I'm wondering how I can view screenshots that I've attached to my scenario results?
After('@browser', async function (scenario) {
if (scenario.result.status === Status.FAILED) {
const b64 = await this.driver.takeScreenshot()
await this.attach(b64, 'image/png')
}
await this.driver.quit()
})
*Thread Reply:* @Alexandros Katechis In the directory mentioned in the this.attach method or by viewing the report
Hi Folks please some help me ,How to pass the data from JSON file to the feature file ????
*Thread Reply:* You’d need to leverage hooks and/or stepDefinitions. We’d need more information to be able to help beyond that.
@Rahul Gupta Can you give an example scenario you are trying to solve for? From initially looking at your question, I can't think of a reason why you would need to do so at the feature level compared to the step_definitions level.
I’m not sure exactly what you’re trying to accomplish. Why not just import a JSON file in the hooks/stepdefs/whatever you like?
Unless the data in there is specifically useful for folks to read, may as well push it into json. 🙂
if i have defined some data in before hook assume like var data="cucumberbdd"
you’re just assigning a variable there. To make it available in a step definition, you need to pass it in as this.data = 'cucumberbdd';
Using this adds data to the world which makes things sharable across step definitions.
I'm not as familiar with those, so I can't speak to them. 😛 I've got pretty limited cucumber-js experience. hah. godog doesn't really facilitate this so you've gotta do your own.
we use them to swap out drivers so that this.driver can be whatever we need for a given set of tests
not considering the specific browser drivers, wdio, appium, puppeteer, and I’m working on a POC to add Cypress for funsies.
again thank you , its worked for me
Cucumber doesn’t enter text values. How you interact with your application depends entirely upon the driver(s) you’re using.
*Thread Reply:* in my experience with cucumber, it’s easier to iron out expected behavior with the entire team - designers (UI/UX)/product, quality, ops, automation, frontend, and backend engineers. Also scales much more easily for growing companies. Mocha is fine for unit tests, but isn’t precisely a BDD framework (in spite of the fact that it lists itself as such). I find it’s perfectly useful for unit, but outside of that, I think it tends not to lend itself to scalable infrastructure like cucumber can.
*Thread Reply:* Mocha is very much like RSpec and Cucumber grew out of the RSpec project and it was always meant to be complimentary.
*Thread Reply:* I see, so cucumber is better for end to end integration tests?
*Thread Reply:* Yes. Particularly if you need to be able to show them externally
*Thread Reply:* I’d much rather walk through cucumber with my PO than mocha 🙂
*Thread Reply:* I’d say that Cucumber is better for customers tests (business facing) and mocha is better for programmer tests (technical facing).
*Thread Reply:* https://www.youtube.com/watch?v=XgVwU-HmC_A
*Thread Reply:* I think it varies. There are companies I’ve worked for where Cucumber for devs would have been a huge help. There are other companies where it would have been overkill. Depends so much on the subject matter + complexity of stack + how many distinct teams are working on multiple projects that interact, etc.
*Thread Reply:* My last job was entirely backend.. Not the usual use-case for Cucumber. However, the backend was a knowledge expert engine. Being able to essentially build a DSL for rule conditions -> expected outcomes was surprisingly helpful.
*Thread Reply:* My current team has pretty much only back end services and we use Cucumber. The services contain business logic (i.e. behaviour)
*Thread Reply:* When I say Customer Test and Programmer Test its not about the level of the stack we’re talking about. It’s more about who “owns” the test, who’s responsible for devising the parameters of the test and who really cares about the outcome.
Customer Test could just as easily be Business Test – for me it’s really about whether it describes the business process. It’s for describing what the software does in a way the business can understand.
A programmer test is to help the programmer write the software. It might give confidence of the correctness of the code, it might serve as an example of how to use a function or class, or if your lucky it can give you fast feedback on your design.
I’d expect most projects to have both customer and programmer tests 🙂
Cucumber is excellent for customer tests.
Lots of great stuff here on the c2 wiki: http://wiki.c2.com/?CustomerTest http://wiki.c2.com/?ProgrammerTest
*Thread Reply:* Yes, I understand the difference between programmer and customer tests, and that they're not tied to the level of the stack. E.g. in my previous team we had unit tests on front end logic. I'm just saying that Cucumber can be used at different levels of the stack. I've used it on front end and back end.
*Thread Reply:* A misconception I notice is that Cucumber is for front end (only)
@Leo While they both run tests, they ultimately serve different purposes
*Thread Reply:* you worded that much more succinctly than I could XD
Hi, I am using cucumber with protractor. In my config file I have defined a couple of test suites (i.e testSuiteA(containing X number of feature files), testSuiteB(containing Y number of feature files) etc). Is there any way to run each SUITE in parallel, i.e browser 1 runs testSuiteA and browser 2 runs testSuiteB and so forth. I would also want each feature file within each suite to run sequentially in the same browser.
Currently I can get multiple browser instances running, but they are each executing different feature files of the same test suite. I want to be able to specify the exact test suite to run for each browser.
@Andrew You'd need to use something that parses your feature files and then manages to run them separately. Cucumber doesn't do this on its own, however. He's not in this channel, but try reaching out to @enkessler as he's got some tools for parsing gherkin
HI , does anyone know a good plugin/package I can use to re-run failed scenarios x number of times for cucumberJS?
*Thread Reply:* how can i do what using the webdriverIO framework with wdio test runner?
*Thread Reply:* I think you have answered my question before but I cannot see the history from the free version of slack haha
*Thread Reply:* if you’re using wdio runner, check out their config docs for the version you’re using (If you’re <5, you’ll need to check the boneyard).
*Thread Reply:* in my company’s initial automation project, we had a config for that, but it’s so deprecated that it may no longer be the same 😉
*Thread Reply:* but ther is no otpion with wdio to re-run entire scenarios, there is only the option to re-run individual steps..
*Thread Reply:* I am using version <4 , v5 is not supported with wdio-cucumber yet haha
*Thread Reply:* hm, afaik, retry for the entire scenario is not readily available as a config option for cucumber. Ideally, you’d want to eliminate the flakes in the test, but obviously teams don’t always have the ability to do so if there are outside dependencies causing flakes 😉 I’m wondering if, in lieu of retry scenario support, one could capture the failing scenarios and kick off another cuke run using only those failed scenarios.
*Thread Reply:* Let me rephrase: One could do this. I’m just not sure what implementation surprises would be in store 😛
*Thread Reply:* I was able to have the test framework kick off a re-run of all of the failed feature files by adding a custom reporter in webdriverIO to track all of the failed features (feature file that contain failed scenarios), however I was not able to find a solution to have the automation re-run the failed scenarios only
*Thread Reply:* Do you mean wdio-cucumber-framework, or running cucumber with webdriverio under the hood?
*Thread Reply:* can you help me with the set up proces? i am running into alot of isseus setting up
*Thread Reply:* yes, so i am able to find my step definitiions in the project by ctrl- clicking them
*Thread Reply:* however when i try to run the project i get the error that my steps cannot be found, can you show you run configurations? This is the error i am getting telling me that my steps are undefined
*Thread Reply:* https://github.com/webdriverio/wdio-cucumber-framework#cucumberopts-options Read these and make sure you’re passing the step defs into cucumber properly
Hi everyone, have anyone used https://www.npmjs.com/package/scroll-js for the scrollnToView method and got it working? I need to scroll a long page to certain sections and assert text in one of my tests. I use selenium-cucumber.js
scrollIntoElement: function(text){
const element = shared.helpers.getElementWithText(text);
scrollIntoView(element, {duration: 1000}).then(function () {
console.log('Finished scrolling to required text');
});
}
```import { scrollIntoView } from 'scroll-js'; ^^^^^^
SyntaxError: Unexpected token import at createScript (vm.js:80:10) at Object.runInThisContext (vm.js:139:10) at Module.compile (module.js:599:28) at Object.Module.extensions..js (module.js:646:10) at Module.load (module.js:554:32) at tryModuleLoad (module.js:497:12) at Function.Module._load (module.js:489:3) at Module.require (module.js:579:17) at require (internal/module.js:11:18)```
*Thread Reply:* @Cat : I don't know what that is. Can you give some context?
*Thread Reply:* https://babeljs.io/
*Thread Reply:* cucumber-js docs have some info on this as well - you have to transpile your code if you’re wanting to use import etc.
I tried to fix it by using const { scrollIntoView } = require('scroll-js'); instead of import.. but this did not help
does anyone here know how I can maybe pass a JSON to my steps file from the feature file?
*Thread Reply:* There’s a convo about something similar in this channel - just search in this channel for “json” - it was, I think, 1-2 weeks ago
*Thread Reply:* @Cat, I see, so instead of passing it from the Feature file what I can do instead is just import it direct from a variable.js file exported as json, which would work in my case since I am not looking for the clients to read it anyways.
*Thread Reply:* yep. And if you had multiple files you may need to switch between, you’d just pass in the name (or path + name) of the one you want
*Thread Reply:* What usually helps me when I bump into something that seems ridiculous to implement in cucumber is to step back and go “What am I actually trying to do as a user in this step?” That usually helps you spot the stuff that is too deep into implementation details rather than describing a business use-case step. if what you’re actually needing to do is denote that you are, say, interacting as a particular user profile (e.g., “I am logged in as an admin”), it makes a lot more sense than saying “I send POST /api/login with this JSON: {…}” Same concept 😉
*Thread Reply:* I actually follow the format of passing the name of the file in the feature file into the step
Given I post item "new jacket" into my cart
The step will then clean the string to be newjacket.json and look in the directory "/testData/item/newjacket.json"
It allows a step to be dynamic and allow user readability
*Thread Reply:* Thanks. I agree. 😛 https://cucumberbdd.slack.com/archives/C6QJ6N695/p1553098033054900
*Thread Reply:* If anybody wants to add this to the FAQ in the docs that would be really awesome! It seems to be a question we get more often (and then we can just point them there).
*Thread Reply:* @mlvandijk I’ll see if I can swing some doc updates soon-like
*Thread Reply:* Sidenote: (for strongly types languages,) I'd suggest using domain objects with builder pattern, rather than json files. I mean, why manage json files when you can have (compile time) checks on whether your objects are correct.
Hi! "Guys" is easily replaced with the more gender-neutral "Folks", "All" or "Foolish mortals". We'd appreciate if you tried to use that. Thanks!
what is a good reporting service to use with cucumberJS and webdriverIO? I tried allure, but it took a really long time to generate reports, so went ahead and moved over to "multiple-cucumber-html" which is actually somewhat janky
@Raymondbut it seems like most of those are not used for javascript frameworks
what do you guys think of this one? https://www.npmjs.com/package/cucumber-html-reporter
*Thread Reply:* I have used that one before. It's good but all depends on your requirements. Also the non javascript ones can still work if you have the jar I believe
*Thread Reply:* @Raymond, how did you generate the JSON report for this framework? after creating the JSON report, if you were to have a rerun of all of the tests, how were you able to merge the objects?
*Thread Reply:* I don't follow your question what do you mean merge the objects?
*Thread Reply:* @Raymond, let me clarify, so I run my tests one time and the cucumber-json reporter will create one json results object for me, and then say i have re-run logic implemented in my code so when I run it again, it creates a new JSON file for me. So far what I am doing is I am combining them using deep merge and using the result of that to create my html-report. However, the issue with doing that is the deep merge will create duplicates. I wondering if you have done anything similar in the past and if you have then maybe you can point me in the right direction
*Thread Reply:* @Raymond, I was able to find a solution for this issue by writing a custom report merger 🙂
Hi! "Guys" is easily replaced with the more gender-neutral "Folks", "All" or "Foolish mortals". We'd appreciate if you tried to use that. Thanks!
@Leo The best input about a particular tool is likely going to be your own, so give that one a shot and see how it goes. 🙂
yes @Gem, love the name by the way, i will try to create my own report 🙂 haha
@Gem, any idea on how I can grab the json from cucumberJS though using webdriverIO? the format property does not seem to work for me
I need help on cucumber integration with puppeteer. I need some documentation or study material. can somebody help me on this?
@Kalyan Roy you can invoke puppeteer functions/methods from Cucumber.js step definitions. Is there anything in particular you’re unsure about?
@Aslak Hellesøy I want to make it configurable. based on some configuration it will take seleniuv-webdriver or puppeteer. So i am searching for any config related file to drive this.
*Thread Reply:* That wouldn’t be a pre-built config, precisely. We do something similar by abstracting out the drivers and swapping them in a before hook using tags. Less of a cucumber question and more of an abstract implementation question.
Hi, i was wondering if there was a way to specifically run certain scenarios by using tags?
@Leo cucumber --tags "@foo or @bar" - see https://docs.cucumber.io/cucumber/api/#running-a-subset-of-scenarios
Hi all, is there a way for me to pass a parameter in a before/after hook in cucumberJS?
but i wish to pass a parameter through that so that i can use conditional statements to determine which endpoint to hit
Possibly, though be careful about exposing too much unneeded detail in your feature file. 🙂
Hi!, I see that in (cucumber-jvm) JSONFormatter.java, the JSON can print "Keyword":"Scenario Outline" , when an Scenario Outline. But in (Cucumber-js) https://github.com/cucumber/cucumber-js/blob/master/src/formatter/json_formatter.js the Keyword for any scenario is hardcoded as "Scenario".
Do you know if "Scenario Outline" as Keyword will be deprecated? Or if I implement the diff for JS could be accepted as a PR?
Afaik as of Gherkin 6 Scenario will be a synonym for Scenario Outline. It is already a synonym for Example. In effect the difference will/should disappear as each should run as an individual scenario/example.
Exactly, I thought, I read something like this. Thank you! Then I will find another way to solve my problem 🙂
Yw. I am curious though what your use case is to know the difference between a scenario and a scenario outline?
They should boil down to technically the same thing (a runnable example)
I have a process that generates the test cases in Jira, from the execution report, and we use the tags to create fields like "data creation"/"Reviewer".... And we treat as only one testCase all the samples from a Scenario Outline.
@InternalTcId:8735e7c4-5f89-45cc-bcc4-d277df05d75f @Author:marta170 @CreationDate:2018-08-08 @Approver:perezlg1 @Reviewer:aparicc1 @ReviewDate:2018-08-09 @Requirement:8774
Ah yeah, I figured you might be counting the outline as one test case rather than multiple.
The problem here is that as the InternalTcId should be unique, but in scenario outline, we have the same id for all the samples
@s2oBcn Cucumber compiles gherkin into pickles - you can think of a pickle as a test case - each Example table row, applied to a Scenario Outline is a pickle.
It might make sense for your process to use the same model.
I'm curious (always): how would you count a scenario outline where some cases pass and some fail?
We are in a regulatory environment, where we have a lot of auditories to verify that there are no errors in our code. So have to generate a lot of documentation from our tests, and we only generate this documentation when everything is ok, in the final release. So, at this stage, we can not have any fail. This is the reason why I don't count the fails in a scenario outline... Of course, we have other reports where we can see which one could fail 😉
@tooky yeah, I know. I was curious how @s2oBcn counts them as I was under the impression the outlines were counted as one test case
can someone help me with an issue i am having with webdriverIO adding a custom command?
I know this is for cucumber only, but i was just wondering if someone here would have any experience doing this
We’ve done something similar, but our implementation is entirely different and probably wouldn’t help much (we use abstracted drivers to switch out as needed). I suggest the webdriverio gitter channel
I have just tried the gitter channel, they seemed to be more focused on using v5, which has this feature built in already, but cucumberJS does not have support for v5 yet
*Thread Reply:* Incorrect. Cucumber doesn’t care what version of wdio you use. The wdio runner that wraps cucumber, however, has not been updated for wdio v5 compatibility.
*Thread Reply:* I mean, not immediately because it’s a private repo, I’m on vacation, and I don’t have time to hop on and build a public example repo. ;) But in addition, if you’re using the wdio runner, my implementation is going to be entirely different.
*Thread Reply:* @Cat, no worries , I found a work around for this issue by simply just adding an external function even though it may be a bit of a dirty fix it seems to get the job done
Hi! "Guys" is easily replaced with the more gender-neutral "Folks", "All" or "Foolish mortals". We'd appreciate if you tried to use that. Thanks!
*Thread Reply:* in the afterhook, how can i see if a scenario passed of failed? @Cat
*Thread Reply:* After({}, async function(scenario) { scenario.result.status });
Hola Cuckes!
Suppose i have a datatable in my step as such where it validates a dynamic message, is there a delimiter that hides the delimiters?
Then the message is <message>
Example:
|message|
|"Field one" is successfully updated|
I want the cucumber output to be displayed as
Then the message is Field one is successfully updated
but the field one can change depending on the field being updated
*Thread Reply:* it would eliminate the need for the quotes in the feature file
*Thread Reply:* Ahh i didn't word my question correctly. I already have steps where i am using regex in the step def to read values from feature file.
The question above was, if there was a way to delimit a word in a string. but not show the delimiters in the runtime output.
*Thread Reply:* Hm. custom formatter perhaps? https://github.com/cucumber/cucumber-js/blob/master/docs/custom_formatters.md
*Thread Reply:* What's the end goal you're trying to accomplish? We know the what of what you're trying for, but that doesn't always equate to the end goal.
*Thread Reply:* If it's just for readability, are the quotes that bad? Could you spin it so that they're meant as an emphasis for what actually matters in the test?
*Thread Reply:* The end goal is to have the quotes (or any delimiter) out of it during the runtime. But i will need to check the value within the string matches the code table.
We have different screen, which use the same id for an button element, but depending on when the screen is accessed, the button name can change. The possible names for the button is stored in code table. same goes for any success, warning messages that apprear
*Thread Reply:* This is mostly for readability. For example, a message says "BID RATE should be greater than $1000". Here i want to check that BID RATE is in the code table for that screen. right now, i have "<<BID RATE>> should be greater than $1000" and i check the string between << >>.
*Thread Reply:* Right, I get that. But it seems like it would be a lot simpler to ditch the delimiters. It’s an awful lot of engineering to ditch them in the output when they could just be avoided entirely.
*Thread Reply:* @Cat That's true, i am not sure how else i would validate a partial value within a string..and the location is not the same on all messages
*Thread Reply:* That means i will have multiple steps depending on the location of the value in a string
*Thread Reply:* i was looking to create a common steps such as
And display success message as follows "BID RATE should be greater than $1000"
*Thread Reply:* which is what we have right now..except the value to be that needs check is between <<>>
And display success message as follows "<<BID RATE>> should be greater than $1000"
And display success message as follows "<<BID RATE>> is same as <<BID OFFER>>"
*Thread Reply:* yeah, you can feed into the stepdef using regex, then in the stepdef (or, probably more extensible, some helper(s)), you’d apply some further regex logic to the params in order to validate
*Thread Reply:* Getting more comfy with regex is definitely a great skill to have and I'm not even talking about looking ahead or anything like that. Cucumber School has a video on the basic things you'd need to work with Gherkin and it's a pretty short list. Expand on that a little with using something like regex101.com and you'll be pretty powerful!
*Thread Reply:* Also, is it truly valuable that the actual messages that are output are put in the feature file or are you more concerned that a process was successful? If it's the latter, then move the data check out of the feature file. Your step can then change to a more broad Then the update process will complete successfully and if you really want to, you can run an assertion against the message in a helper file called by the step def.
This way you're removing the headache you're currently facing, removing potentially unuseful data from whoever ends up reading the files, AND you're decoupling yourself from the specific message text at least somewhat. If you want to check the message, you can setup a json file or something and read that in or just do a string.contains(foo). Either way, it lessens the impact on future maintenance which is 👍 🙂
basically, i want to parse a string with a delimiter, that does not show up in the output.
i have this in my feature Then <<Price>> must be greater than or equal to 100.
The out put would be
Then Price must be greater than or equal to 100
Has anybody here got much experience with the cucumberjs parallel feature? What I want to do is lazily create and store data across all tests for reuse using a singleton pattern but what happens is that eash of the node containers for each of the parallel runs creates it's own data collection singleton. Is there a way I can set the data to be shared across all containers?
hello, guys could someone please advise me on the following? I've updated to later version of cucumber-js, which is 4.2.1 (previously I was using 1.3.3) Now I am struggling to retrieve some scenario execution data I need to report to TestRail. The kind of data I need:
what would be the best way to get all this? previously I was retrieving this in hooks
I am using a Singleton pattern to register EventEmitter events in my React app. When I test the services which register these events on the Singleton, I am instantiating the services' constructors in the World file. However, I only need certain constructors in each test, not all of them as provided by the World.
I have attempted to use Before hooks to set the constructors I don't need in any given scenario to null but the events are still registered, likely because World is running first.
Is there any way to conditionally instantiate constructors within the world based upon which scenario is running?
*Thread Reply:* If using a singleton pattern then why set it in the world instance? That will register it in every test which defeats the purpose of the pattern. I would recommend registering in the BeforeAll hook, which would mean every test has access to the Emitter
*Thread Reply:* I am using cucumber v4.2.0 and junit v4.12. Any suggestions please.
AfterAll(async function() { // Teardown browser if (this.browser) { await this.browser.close(); } });
Hi there!
Could you advise are there any sites or repositories with various examples and exercises to practice Cucumber and Gherkin (in JavaScript) ?
Thanks in advance!
P.S. Please do not mention the official documentation 🙂
*Thread Reply:* Are you looking for a specific focus? There are some fairly straightforward examples like this one https://www.sitepoint.com/bdd-javascript-cucumber-gherkin/
*Thread Reply:* Because, it is an obvious option 🙂 It doesn't mean that it is not important.
*Thread Reply:* What - if anything - are you missing in the official documentation?
Can some one help on above qution plz @api @ns Feature: Smoke test @basic @positive [%- INCLUDE "completed/useraccess.feature" %] @basic @advancecase1 [%- INCLUDE "completed/cookie.feature" %] [%- INCLUDE "completed/get_price.feature" %] Scenario: I need some extra logic before next feature file Given that this is required Then i need to enable service [%- INCLUDE 'completed/modify.feature' %] [%- INCLUDE 'verification.feature' %] [%- INCLUDE 'renewal.feature' %] [%- INCLUDE 'autorenew.feature' %] [%- INCLUDE "completed/privacy.feature" %] [%- INCLUDE "completed/password.feature" %] [%- INCLUDE "completed/subuser.feature" %] [%- INCLUDE "completed/lock.feature" %] Scenario: Ones test's are completed Given I need dome extra scenarios for this feature only Then I will include them here. And plz let me know weather this INCLUDE IS usefull or not
does anyone know the default install location of mocha when you install it via apt-get on bionic?
trying to get rubymine to play typescript files and it's throwing 1000 errors about runners and suchlike (I'm a bit out of my depth)
Is anyone using cucumberjs in a typescript project and having trouble with the World instance losing its types? I can access the variables stored on the world instance but they all come through as any instead of the types set on the custom world instance when accessing them in step definitions
mock in browser time to test time specific actions/behaviors within the browser?
So in the application I am testing there is this feature where a certain option should only be visible after 6 PM
I wish to inject a time into my browser so I can test for that functionality from an e2e perspective as opposed to unit testing that functionality
One thing, I would say to be careful of it if running in parallel that may cause issues
Is there anyway for me to mock browser time only Because it will break others tests when running in parallel
Actually, now that i think of it, I think there may be a way to launch the browser driver with a particular time zone. Check the config options for the driver you use.
i know that there is a way to launch a browser with a specific timezone @Cat, i am already setting that option in my capabilities for chromedriver haha, but is there a way for me to launch a browser with a specific time?
you could use a lib like this one: https://github.com/boblauer/MockDate
https://sinonjs.org/releases/v1.17.6/fake-timers/
but I have been told by others that sinon is a mocking service used for unit testing only and not much can be done for e2e testing with that framework
There are definitely cases where sinon can be used to mock things that are basically setup for an e2e case, but if this is your use-case and you don't have a ton of other tests that would lean on sinon, it's almost certainly not worth the setup 🙂
like the date object in my test is changed during runtime, but the in browser time (which grabs the time from my system time) is not modified and
Hm. My suggestion would be to either test it at a lower level so you can mock it, or run on VM so that modification of the system time won't impact other tests.
https://markus.oberlehner.net/blog/network-stubs-and-timers-with-nightwatch-and-cucumber/
@Cat is it possible to user nodejs to inject javascript into the html headers of an application?
Because node can do TONS of fancy stuff, but the browser isn’t a node environment ;)
because that is basically what that article is doing, except in my case, i dont actually access to "index.html" so i cannot simply just spin up a test server and have it inject timer.js into my header @Cat
@Cat I basically want to inject this script into my application under test during runtime, without actually having access to the applications source code however
Hey. I am running my tests with cucumber-html-reporter and I am unable to take a screenshot and attach it to be the report https://github.com/gkushang/cucumber-html-reporter Following the instructions, I receive the following error "world.attach is not a function"
*Thread Reply:* Make sure you are passing in params to your custom world instance constructor and then make sure to create this.attach = params.attach
So, I think I am on the right track, but I am still not able to figure it out, i have posteed a stack overflow question here, any help would be greatly appreciated!!!
@Leo Here is a suggestion that I will know will work, but it is up to you if it is worth the effort (It is similar to Cat's suggestion about using a VM). Create a docker container, set the system time of that container, and run the corresponding tests within that container. Would make your test truly E2E, as from what I have read, the browser gets system time from the OS (and not the browser). Otherwise for simplicity, test the time functionality at a unit or integration level. Example: If you were using React, render the page with a mocked out time, and see if the DOM matches what you were expecting.
@Nick Gonzalez Where did you place your ... world = this variable? "world.attach is not a function" error might be occurring, because "this" can correspond to a different context depending on where you place that line in the code.
@Andy Nguyen, I'm not sure if I would be able to render the page with a mocked out time, because I don't think I have access to the src code
I am only testing the application, I do not access to the source code, but what I can do is give you the html from the chrome inspector @Raymond
*Thread Reply:* Yep that would be helpful. You may be able to override the value being used if it's being done on the frontend
@Andy Nguyen The this is happening in the After function of the World.js file
@Nick Gonzalez https://cucumberbdd.slack.com/archives/C6QJ6N695/p1559840687040800?thread_ts=1559779719.027600&cid=C6QJ6N695
*Thread Reply:* @Nick Gonzalez no it would be in the CustomWorld constructor
*Thread Reply:* export class CustomWorld { protected constructor(params) { this.attach = params.attach; } protected attach; }
*Thread Reply:* My custom world is not a class. It is a function function CustomWorld(callback) { this.driver = new webdriver.Builder().forBrowser("chrome").build(); }
*Thread Reply:* Okay try the following function World({attach, parameters}) { this.attach = attach; this.parameters = parameters; this.driver = new webdriver.Builder().forBrowser("chrome").build(); } setWorldConstructor(CustomWorld)
Hey, I made a small sample project for how to use the pageObject pattern with cucumber.js. I thought maybe someone on here could use that as well. You can check it out on https://github.com/tobysoby/cucumber-js_pageObjects_example All feedback is welcome of course! 🙂
*Thread Reply:* @tobiasdoll You have put page objects under the feature directory, that is bad practice. They should go under a page directory or a step definitions directory
*Thread Reply:* @Raymond thanks for that. But why exactly is that bad practice? Can't all test code live in features? (Like in the official nodejs example, see https://github.com/cucumber/cucumber-js/blob/master/docs/nodejs_example.md)
*Thread Reply:* @tobiasdoll The feature folder should include only feature files and no ts/js/** code. The code such as steps / pages should live in their own folder as it muddys the water putting everything into the same folder.
Is there a way to include an integer in a feature's scenario without it passing to the step definition?
I’m not sure I understand your question @Nick Gonzalez. How would you access it from the step definition if it’s not passed to it?
@Aslak Hellesøy I know it sounds strange, but the particular phrase that I'm using in the scenario merely has a number in it
Ok? So just repeat that number in the stepdef’s expression rather than making it a parameter.
You don’t have to use the stepdef cucumber suggests. You can edit it/write your own.
Hi! "Guys" is easily replaced with the more gender-neutral "Folks", "All" or "Foolish mortals". We'd appreciate if you tried to use that. Thanks!
Is it possible in CucumberJS, to pro-grammatically TAG the failed scenarios, and then have the framework RERUN only the failed scenarios with a certain tag?
I have a few flaky scenarios that sometimes fail and sometimes do not fail due to application network issues, and I was wondering if there was a way for me to rerun only those failed scenarios on a second or even a third retry sometimes
*Thread Reply:* https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#formats Rerun
*Thread Reply:* is this something I can do with the wdio-cucumber-js framework? @Raymond
*Thread Reply:* @Leo can you link me that repository and I can take a look
*Thread Reply:* @Raymond https://github.com/webdriverio/wdio-cucumber-framework#cucumberopts-options
*Thread Reply:* I am going to try to pass the retry logic as a cucumberOption right to see if that will work for me, even though i couldn't find it in the documentation from that link
*Thread Reply:* this is what my cucumberOptions look like
cucumberOpts: { tagExpression: '@QA', format: [ 'rerun:@rerun.txt' ] } }
*Thread Reply:* so after doing alot of research yesterday, I figured out why it was not working for me. It is due to this issue: https://github.com/webdriverio/wdio-cucumber-framework/issues/6 , webdriverIO apparently blocks cucumberJS reporters, and because of that , I am not able to format the rerun.txt file. However, I was able to find a work around by having my automation retry entire failed feature files instead. It takes a bit longer, but definitely gets the job done. Anyway, thanks for your help!
@Leo Cucumber does support rerunning failed scenarios. 🙂 I’m not sure about using it with the wdio-cucumber-js however. I’m not familiar with that.
One thing I will add that’s tool independent though, is that you should be much more concerned with improving the flake tests. Improving the resiliency of your tests with things like network failures is hugely important as they should not be failing for things outside of what’s being tested. Also, you risk losing team confidence in test failures which defeats the purpose of having them in the first place.
UnhandledPromiseRejectionWarning: NoSuchElementError: Unable to locate element: **[id="btnLogout"]
That means the element with the mentioned id is not available at the moment the test is looking for it. You might need to wait for it to become available (using a fluid wait, not a sleep) or use a different locator.
Apologies if it's been mentioned before, but what is the best solution for cucumber reports when running tests in parallel? The default option outputs the steps results as soon as they complete, which works fine in serial but not so well in parallel.
Hi All. I'm starting with CucumberJS but only see examples using the assert built-in module or chai. I'm currently using Jest for unit testing. I've doing some research about integrating CucumberJS and Jest and found a couple libraries, unfortunately don't see to work well.
How do you people work with that? Should I use two different libraries for testing? or migrate to chai in order to support my step definitions? Also I'd like to see some example projects with JS doing so. Thank you very much.
*Thread Reply:* Short answer to "How do you people work with that?": I don't. 🤷 Long answer: Any time "my unit tests are in x so I want to keep using x with cucumber" is typed, god kills a kitten. When we write BDD tests like unit tests - to the point of wanting to retain our unit testing framework - it tends to result in tests that are also designed like unit tests, which lends itself to being nothin-but-anti-patterns when it comes to testing that is above unit level. My suggestion (and what I and my team do) would be to use an assertion framework that plays nicely with Cucumber (we use chai here). You can try to figure out something with jest, but imo, it's a lot faster to just use an assertion framework 🤷
*Thread Reply:* You're right, Cat. Faster and easier. Thank you so much for you advice.
Can the running order of cucumber-js hooks be configured somehow? I tried using what was suggested here, but without much luck... https://www.toolsqa.com/cucumber/execution-order-hooks/
*Thread Reply:* If I recall, before hooks run sequentially - after hooks are reverse sequence.
*Thread Reply:* So the top before hooks run first and the top after hooks run last?
*Thread Reply:* Yep. Have a look at the docs: https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/hooks.md
Is the timeline-formatter available in cucumber-js? https://cucumber.io/docs/guides/parallel-execution/#timeline-formatter
*Thread Reply:* There's no "official" offering, to my knowledge. There's a cucumber pre-processor for cypress.
*Thread Reply:* I see cucumber plugins for Cypress here > https://docs.cypress.io/plugins/index.html
*Thread Reply:* Here’s more info around official and other offerings of Cucumber. 🙂 https://cucumber.io/docs/installation/
Hi! Our Customers want to write features in German. I know that I have to use #translate: de. - That works in my IntelliJ Idea without any problems. But if I create the step definitions I’m getting following errors:
e2e/src/features/step_definitions/app-test.steps.ts(3,10): error TS2305: Module '"../../../../../../../../Users/joerg/Werkstatt/leia/node_modules/@types/cucumber"' has no exported member 'Angenommen'.
e2e/src/features/step_definitions/app-test.steps.ts(3,30): error TS2305: Module '"../../../../../../../../Users/joerg/Werkstatt/leia/node_modules/@types/cucumber"' has no exported member 'Dann'.
e2e/src/features/step_definitions/app-test.steps.ts(3,36): error TS2305: Module '"../../../../../../../../Users/joerg/Werkstatt/leia/node_modules/@types/cucumber"' has no exported member 'Wenn'.
*Thread Reply:* If I'm not mistaken, the gherkin can be in any language, but the step definitions would still call the same things (e.g., Given, When, Then). alternatively, you can use defineStep. But it looks like you're trying to import things that don't exist in the cucumber library.
*Thread Reply:* I thought, if my IDE is giving me that file, I can use it as it is.
*Thread Reply:* That looks like it might be a bug in either the IDE or the snippet generation. How was the file created?
JavaScript will allow this to work though! You can change line 3 to:
import { Given as Angenommen, Before, Then as Dann, When as Wenn } from 'cucumber';
😄
*Thread Reply:* Isn't is the other way around?
import { Angenommen as Given, Before, Dann as Then, Wenn as When } from 'cucumber';
*Thread Reply:* Ah seems on imports it's the other way around. I learned something today 😄 thanks @tooky
*Thread Reply:* See?! Everybody learns up in here! https://media.giphy.com/media/3og0IMJcSI8p6hYQXS/giphy.gif
Hi, I want to create a cucumber-html-reporter and take a screenshot of the results. Is anyone willing to give me a hand ? Like with a simple cucumber scenario
*Thread Reply:* Screenshot at the last step or screenshot at the failed step?
*Thread Reply:* Screenshot at any point 😄 I am new to this and I do expirements
*Thread Reply:* I run my index.js file with node index.js and I get an error that takeScreenshot is not a function 😕
*Thread Reply:* Then you will need to parse the image data
imageStream.write(new Buffer(data, "base64"));
imageStream.end();
*Thread Reply:* here is a screenshot at failure implementation
if (scenario.status === "failed") {
await browser.takeScreenshot()
.then(async function (screenshot) {
decodedImage = screenshot
await saveScreenshotToLocal(scenario, screenshot)
})
}
export async function saveScreenshotToLocal(scenario, screenshot) {
const fs = require("fs");
const path = require("path");
const dir = "./e2e/reports/screenshots";
const now = new Date()
const hours = (now.getHours() < 10 ? "0" : "") + now.getHours()
const mins = (now.getMinutes() < 10 ? "0" : "") + now.getMinutes()
const sec = (now.getSeconds() < 10 ? "0" : "") + now.getSeconds()
const ts = now.toISOString().replace(/\T.**$/, "").replace(/-/g, "") + "_" + hours + mins + sec
//create folder screenshots, if it doesn't exist
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir)
}
// Writing screenshot to a file
function writeScreenShot(data, filename) {
const imageStream = fs.createWriteStream("./e2e/reports/screenshots/" + filename);
imageStream.write(new Buffer(data, "base64"));
imageStream.end();
}
const featureFileName = ((scenario.scenario.uri).split(path.sep))
writeScreenShot(screenshot, featureFileName[featureFileName.length - 1] + "-line" + scenario.scenario.line + "-" + ts + ".png")
}
Hi Everyone, Is there any cucumber reports where it reports by tag? for ex: @defect - 32 failed, 2 passed and so on
*Thread Reply:* So it must be a joke-app. I tried to download it, because it was like an enviroment especially for cucumber, and no matter how many times I click on Download it'll never does anything. So it may be a fraud 😛
Does anyone has to suggest me a tutorial when I can easily make a cucumber html report ?
*Thread Reply:* Should be covered in the docs - if you need something additional, look at npm for cucumber html reporter
Why I keep getting "cucumber command not found" when I try to run cucumber? 😕 I've installed it with these commands
*Thread Reply:* https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md
Ditch the global installation.
*Thread Reply:* So should I uninstall cucumber and re-download it but not globally
*Thread Reply:* global uninstall (if you aren't familiar with that, check the npm docs).
Install it at the project level - npm i cucumber or npm i cucumber --save-dev is fine
*Thread Reply:* then you can just follow the instructions from that doc I linked
*Thread Reply:* Sooo.. that worked! Now I want to make a html cucumber report and although I follow the steps at https://www.npmjs.com/package/cucumber-html-reporter I keep getting error Unable to parse cucumberjs output into json: './htmlreport/hellocucumber/nodemodules/package.json' Error: ./htmlreport/hellocucumber/nodemodules/package.json: ENOENT: no such file or directory, open './htmlreport/hellocucumber/node_modules/package.json'
Any suggestions?
*Thread Reply:* Unable to parse cucumberjs output into json: './htmlreport/hellocucumber/package.json' Error: ./htmlreport/hellocucumber/package.json: ENOENT: no such file or directory, open './htmlreport/hellocucumber/package.json'
*Thread Reply:* ... what? You don't need to add node_modules. npm creates that
*Thread Reply:* I'm learning 😛 But, still the main error keeps showing itself
*Thread Reply:* I would recommend deleting your node_modules folder, run npm i from the project directory, and then looking at the configuration docs for the formatter you're using
*Thread Reply:* FML I don't get it. I'll study more and come back to retry 😜
*Thread Reply:* nah, you just don't have muscle-memory for debugging npm yet 😂
*Thread Reply:* 😂 Anyway, thanks for your time and your help, I really appreciate it! Farewell Cat 😻
Why every video about cucumber-html-reporter in YT is for java? No one wants to do it with JS?😑
*Thread Reply:* Just check npm for the reporters. The README will be pretty straightforward
@dimliaro we’ll soon start working on a new HTML reporter that will work across all Cucumber implementations. And hopefully a lot better than the existing implementations.
Sooo, I did manage to create a cucumber-html-report by following instructions on the internet. Well, thats what I thought... I ran :
And the results are that I have the same file but with different name and filename.type.
Despite the fact that that's not a problem, my goal was to create a bootstrap pie scheme that shows me stuff. And though I thought that when I ran it, a window will appear and show me the pie scheme that I saw on the internet. But that never happened.
I don't know if any of you can help me or give me a thought, but If you read this I thank you for spending time even reading it 😛 PEACE
*Thread Reply:* you could just run npm run yourTestScript && open yourHtmlOutput.html
*Thread Reply:* (you'd need to use npm-run-all dependency if you want to execute that from your package.json)
Hi, I am trying to use click method for a scenario to pass. If I was JS what commands would I use? 😛
*Thread Reply:* Well, technically I want to implement in js this scenario: Scenario: Given that I have gone to the intelligencia page When I click on Request a Demo Then I should see a picture
And I can't do the Given part, when I use click() , i am getting error click is not a function
*Thread Reply:* Cucumber doesn't give a shit WHAT you're doing 😛 you have to tell it what you're doing.
*Thread Reply:* Yes, but not in cucumber because cucumber does not click anything. 😛 I can tell you how to click in webdriverio
*Thread Reply:* // #/Users/dimitrisliaropoulos/Desktop/htmlreport/hellocucumber/features/step_definitions/stepdefs.js var {setDefaultTimeout} = require('cucumber'); setDefaultTimeout(60 ** 1000); const assert = require('assert'); const { Given, When, Then } = require('cucumber'); const {Builder, By} = require('selenium-webdriver'); let driver = new Builder().forBrowser('chrome').build(); var chrome = require('selenium-webdriver/chrome');
function clicky(){ document.getElementById("nav-request-demo").click(); }
Given('that I have gone to the intelligencia page', async function() { await driver.get('https://www.intelligencia.ai'); }); // When('I click on Request a Demo', async function() { await driver.getElement(By.linkText("nav-request-demo")); }); // by class? Then('I should see a picture', async function() { driver.findElement(webdriver.By.class("hero-img-2 section")); });
*Thread Reply:*
function clicky(){
document.getElementById("nav-request-demo").click();
}
you're using document and not driver which probably doesn't help 🤷
*Thread Reply:* I was using diver berfore 😛 then i googled searched. I saw the document.blahblah and threw it in
*Thread Reply:* I'd suggest reading the API docs: https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebElement.html
Hi folks, how would you do this. I have page where is dynamic content which is table that is filled with data. Let´s say that I have 5 columns but I can have 1 row or 10 rows depends on number of data. I need to check some item row. Example. - this table is filled with service requests. Each has own unique ID but other fields can be the same. How can I check that service request that is on second like has correct last item in table. Last item can be for example 5th row. I cannot set up fixed selector cause this table is dynamic but I need to check that 5th item in this table is let´s say with some icon like urgent icon.
Shell I set up selector for <tr> then list through all <td> and with forEach check content like innerText and then compare it?
however you think is best.
If it's data available on a website. I'd store the original dataset and then sanitize it.
try break it down into smaller tasks. get all elements get all text sanitize all text
Hi I just want to check can we use cucumber with siesta and if we can use then how to use please reply?
Hey sorry for posting this here and in #help but I didn't know this channel existed until this morning:
Hi everyone, I'm fairly new to cucumber (beyond the basics) so please forgive me if this is a simple issue.
I'm trying to create a new ParameterType which I've set up using the following JS code:
defineParameterType(
new ParameterType(
'actor',
/Robert Price|Test User/i,
Actor,
name => new Actor(name)
)
)
However I get the error ParameterType Regexps can't use flag 'i', flags are not THAT important to me as I can get around that so I tried removing the flag and now I get TypeError: Cannot read property 'flags' of undefined, I can't figure out a way around this but I think I've narrowed it down to the regexpFlags function in cucumber-expressions/src/parameter_types.js.
Has anyone seen this issue before and if so, do you know what the work-around is?
If it helps, I just did a console.log on the regexp parameter and I'm getting this if I try to run it without flags:
/-?\d+/
/\d+/
/-?\d**\.\d+/
/[^\s]+/
/"([^"\\]**(\\.[^"\\]**)**)"|'([^'\\]**(\\.[^'\\]**)**)'/
/.**/
/Robert Price|Test User/
undefined
I have no idea where that undefined is coming from (also no idea where the stuff before my actual regex is coming from either but I suspect it's the undefined that's causing me problems)
with the flag I get the same output except that /Robert Price|Test User/ prints as /Robert Price|Test User/i and there is no undefined line.
*Thread Reply:* Hi @Alexander Foxleigh - the reason you cannot use flags is that the parameter type’s regexp will be merged into a bigger regexp covering the entire step text. Allowing flags such as i would then apply to the entire regexp, which would be undesireable. For example there might be another parameter type for currencies with regexp [A-Z]{3} and we don’t want that to match gbp, only GBP.
*Thread Reply:* As for the error you’re seeing - I’m not sure. What Node.js version are you running this on?
*Thread Reply:* Also, what version of cucumber-expressions do you have in your package-lock.json or yarn.lock?
*Thread Reply:* In order to help you and fix this bug it would also be useful to see a stack trace. Please create a new issue at https://github.com/cucumber/cucumber/issues
*Thread Reply:* The more detail you add, the higher the chances of someone picking up the issue to fix it.
*Thread Reply:* If you submit a pull request with a test that reproduces the bug that would be great!
*Thread Reply:* @Aslak Hellesøy I think the problem is that the team I'm on are using the cucumber-boilerplate library which inexplicably has 3 different versions of cucumber-expressions installed, plus there is a lot of black-box stuff going on behind the scenes which I can't debug. So until I can bully them into dropping boilerplate, I think we're stuck, I'll just have to work around it.
*Thread Reply:* Yuck! I see they reimplemented the training wheels I tossed 8 years ago. This stuff just won’t die! https://aslakhellesoy.com/post/11055981222/the-training-wheels-came-off
Hello fellas, quick and maybe stupid question:
If, for any reason, I have in a feature file two different scenarios with the same Given and on the "stepdef.js" file I write it only once, will it run Given two times?
As an example I could imagine this: Scenario: 1 Given I am on a website When I do stuff Then stuff happens
Scenario: 2 Given I am on a website When I do other stuff Then other stuff happens.
Like, go to a page, do smth and then navigate to same page you were before. But do I have to write again the Given code in js?
*Thread Reply:* No, the step definition is defined once in the code. It will execute when it is called, like any other function.
And tell me how I can "highlight" and send (here in slack) the code or smth else in cute organised boxes 😛
Hi, I got this error
Error: function timed out, ensure the callback is executed within 60000 milliseconds
I had that issue before and I fixed it with
setDefaultTimeout( 60 ** 1000);
Now that I added one extra scenario, it still shows me that message. Any ideas?
*Thread Reply:* Error is pretty self-explanatory. The function is timing out (aka the step is taking too long to complete) either extend the timeout of the individual step or of the overall timeout
Hi all, does anybody knows if there is a simillar Slack group where I can ask JS questions? Like how I can find and click a button when i have this in inspect element?
<button type="button" class="md-btn md-btn--raised md-btn--text md-btn--raised-pressed md-pointer--hover md-background--primary md-background--primary-hover md-inline-block mp-fidelio-login-button"><div class="md-ink-container"></div>Enter</button>
I use
driver.findElement(By.className('md-btn md-btn--raised md-btn--text md-btn--raised-pressed md-pointer--hover md-background--primary md-background--primary-hover md-inline-block mp-fidelio-login-button'));
But I know that it's wrong
Thanks in advance and sorry for the irrelevant post, but i am asking for cucumber purposes
*Thread Reply:* ok, so, those aren't strictly JS questions - they are questions specific to the driver you're using. You would need to look for similar groups for that specific type of driver (e.g., wdio, selenium, puppeteer, etc.)
Hi all The main Idea is: I am on a page and there are two buttons. Each one of them, should navigate me to a different page.
So , I have this code in a feature file:
``` Scenario Outline:I am logged in
Given I am logged in
When I click on <section>
Then I should be in <section> section
Examples: | section | | ATHENA | | FIDELIO |
And this code in stepdefs.js:
``` Given('I am logged in', function(){
driver.get('<http://localhost:3000/demo_dev/loggedin>');
takeScreenshot(driver, "Scenario 2: IamLoggedIn.jpg");
});
When('I click on ATHENA',function(){
driver.findElement(By.xpath('//**[@id="root"]/div/div[1]/div[4]/div/div[1]/div/a/button')).click();
setDefaultTimeout(60 ** 1000);
takeScreenshot(driver, "Scenario 2: IshouldBeInPageAfterClick.jpg");
});
When('I click on FIDELIO',function(){
driver.findElement(By.xpath('//**[@id="root"]/div/div[1]/div[4]/div/div[2]/div/a/button')).click();
setDefaultTimeout(60 ** 1000);
takeScreenshot(driver, "Scenario 2: IshouldBeInFidelioAfterClick.jpg");
});
Then ('I should be in FIDELIO section', function(){
takeScreenshot(driver, "Scenario 2: IshouldBeInFidelio.jpg");
});
Then ('I should be in ATHENA section', function(){
takeScreenshot(driver, "Scenario 2: IshouldBeInAthena.jpg");
});
The result is not what I was hoping. I mean, how can I see if it clicked both of the buttons while testing?The screenshots are the same What am I doing wrong?
*Thread Reply:* If your web driver fails to click an element, you should get an error. Also, instead of taking a screenshot alone, you should actually assert something. 🤷♀️:skintone2:
*Thread Reply:* The state of the application? You could assert based on the visibility or existence of an element, etc.
*Thread Reply:* It's fine to take a screencap, but that doesn't actually tell your tests if they should pass or fail (although they will if it fails to screencap)
*Thread Reply:* for our tooling, we'd do something along the lines of expect(this.driver.isVisible(myElement).to.be.true;
*Thread Reply:* for that use case, wdio would get the visibility state of the element being passed in and, if it returned true (visible) the test would pass. If it returned false, the test would fail.
*Thread Reply:* @Loki every release has a changelog where you’ll find the answer: https://github.com/cucumber/cucumber-js/blob/master/CHANGELOG.md
*Thread Reply:* with version 0.9.5 we were able to invoke parallel execution but report generation on execution impacted as it started overwriting with the last instance execution
Hello everyone, do we have any automation around refactoring steps.js when upgrading from Cucumber version(0.9.5) to latest version?
*Thread Reply:* To my knowledge, no. That's a pretty huge version gap - I recommend looking through the changelog at breaking changes to see what would need to be altered to get from 0.9.5 to current.
Hello everyone, anyone have issues with webdriverIO v5 integrated with cucumberJS for allure?
Adding some more context 🙂
*Thread Reply:* Update: ^ haha thanks, also so maybe I am just not understanding how allure works in general, but when I use the allure command line "allure generate" the report does not generate but when i do "allure serve" it generates the report correctly.
Other than allure for cucumberJS integrated with webdriverIO v5, is there any other reporters currently available?
*Thread Reply:* Cucumber doesn't care what application framework you're using. It just runs the tests. Whatever you tell it to do in the step definitions is what it will do.
*Thread Reply:* In case of Dotnet i have used Spec flow and in the step definition file i have used Selenium. If application is of Sencha what can i use in Step definition.
*Thread Reply:* You would still use selenium unless you needed to use something else. Whatever you put in the step definitions is entirely dependent upon what and how you're testing - not so much of a cucumber question.
Hi, I have a question about the --require flag. I have a mono repo with some tests at the top level and some tests for each package. I'd like to avoid to duplicate multiple step definitions, but from a package I'm not able to require files from the top level folder. Here is the issue I get TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
at assertPath (path.js:39:11)
at Object.relative (path.js:1167:5)
at getDefinitionLineAndUri (/Users/muraw/Company/l2-sdks/node_modules/cucumber/lib/support_code_library_builder/build_helpers.js:184:27)
at buildStepDefinitionConfig (/Users/muraw/Company/l2-sdks/node_modules/cucumber/lib/support_code_library_builder/build_helpers.js:124:7)
at SupportCodeLibraryBuilder.defineStep (/Users/muraw/Company/l2-sdks/node_modules/cucumber/lib/support_code_library_builder/index.js:51:79)
at Object.<anonymous> (/Users/muraw/Company/l2-sdks/tests/lang/ts/step_definitions/steps.ts:11:1)
*Thread Reply:* cucumber-js ../../tests/features --require=./tests/step_definitions/**.ts --require=../../../../../tests/lang/ts/step_definitions/**.ts --format progress-bar --require-module=ts-node/register
*Thread Reply:* per docs and my own code, that flag is --require <myPath>
*Thread Reply:* not sure if it would affect it, but why aren't you in the TLD when running?
*Thread Reply:* in that case, I'd confirm the path. Nothing else should be impacting, from what I can tell
*Thread Reply:* but if I move the top level step definitions to my local package it works
*Thread Reply:* @luke I can't actually because I'm using specific dependencies from the package
*Thread Reply:* root
When I run my tests from package1 I cannot use step_definitions from the top level tests
*Thread Reply:* yes you can, just require something at a higher level than you're at.
*Thread Reply:* ok but I keep getting this error TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
I tried with something very simple:
import { Given } from 'cucumber';
Given('I have a workspace', async function(): Promise<void> {
...
})
*Thread Reply:* in the stacktrace I can see that the error point on the Given(...) line, but I think it has nothing to do with my code because it's working correctly if I move that file in my package
*Thread Reply:* I have the same error if I run from the TLD, btw when I use --require-module=ts-node/register does it use the local tsconfig.json file?
When you’re asking about “integrating” cucumber-js with mocha, what specifically are you asking about?
We already have an existing framework built in mocha and chai. We are looking to automate apis as we lack documentation we are looking towards bdd so we can have documentation and also follow behavior driven format.
I’m not super experienced with the js implementation, but what I know of mocha and its setup, I don’t know if there’s really a way to do that. Keeping chai as it’s mean for assertions is totally doable, but I think you’d likely need to break out the code you’re running via mocha’s setups into (preferably) helper methods that you could then have your step definitions call.
So: You can absolutely maintain chai under the hood. I'd like to know more about what you're trying to accomplish, however. While, no, you certainly would not want to wrap your mocha in cucumber-js (yo dawg, I heard you liked testrunners so I put a testrunner on your testrunner...), there are also some architectural and long-term strategy distinctions that fundamentally differentiate each.
Well our apis lack documnetation and we want our features to be the centralized for how api is suppose to work. So tobaheive this we were thinking of implement bdd using existing mocha chai framework that has existing ui and api tests. Our goal to work under same project so everyone can work in the same framework and transfer of knowledge is also easier.
That totally makes sense and it’s a great endeavor to shoot for, it’s just not going to be a drop in solution. 😛
I’d recommend taking an existing feature and building it in Cucumber without any Mocha so that you can try to get a feel for it.
It sounds like you’re getting hung up on what you want to do with your existing stuff before understanding the tools/landscape of things.
Mocha is a testrunner. Cucumber is a testrunner. Testrunner turducken is not going to make anyone happy 😉
*Thread Reply:* But meant more to illustrate that using mocha within cucumber is a bit superfluous
Define "existing framework". If you just want to use mocha cuz you have mocha in place already, just use mocha 🤷 If you want to use the assertions, helper functions, etc that are underneath mocha, that's a different discussion
Can you give an example of what you would want to cover in cucumber vs. what you have in mocha?
We want to extend the current framework built in mocha chai selenium for ui and request for api to use behavior driven so we can have a centralized features
Yes. Got that. Give me an example of what you have now vs. what you you want from cucumber.
Well we want to automate api testing for a new product which doesnt have any documentation. And we want to follow behavior driven automation for these apis so we can have a centralized documentation
@zsattar1224 You need to help us help you. 😛 Code examples, even if sanitized, could be a great help.
If you just want to automate the API, that's pretty straightforward. What's confusing to me is the "integrate cucumber-js with mocha" statement earlier.
IMO, it sounds like they want to use feature files to drive their existing mocha setup. (Which definitely ain’t gonna work)
Correct. If you’re unable or unwilling to move away from mocha, then you’re stuck. 😞
Hmm i see need to have internal discussion. Thanks for the info though. I really appreciate it
👍:skintone3: Good luck! We’re here to help if you decide to make the switch. 🙂
Hey, guys! Can we please review this PR with this cool feature for cucumber-js community? https://github.com/cucumber/cucumber-js/pull/1205
charlie was taking the lead on that and had some strong opinions on that. So I'll leave it to him
If there are strong OSS js people out there who want to review it feel free.
I'm a rubyist. And I do a bit on the overall stuff, but I'm not too hot on js sadly
In cucumberJS, is there something like a scenario ID or test ID I can store into a variable and then use ? I am using a service built into webdriverIO called visual regression to compare images in my tests, and whenever I take a screen shot and generate a image file, i would like to use that use some sort of unique identifier to name that image with so that I know that this image came from this scenario/test specifically. I am currently using sessionID, but I have multiple scenarios/test per session usually, and therefore session Ids are not unique enough.
*Thread Reply:* I surprisingly can't see access to an id but you can build one based on the scenario such as
*Thread Reply:* This will output something like
spec/cucumber/features/quoting/quotes/modeling/DisplayQuoteCostsData.feature119 which you could then massage into a format you would like for an image name
*Thread Reply:* Also I tested with scenario outlines and the line is unique to each example
I'm not sure, but you could create your own guid to use? You could also do some sort of concat of the particular scenario + timestamp or something, too. 🙂
Hello All,
I’m using Cucumber JS with Protractor. Is there a cucumberOpts option that I can set in my protractor.conf.js such that cucumber can show the full stack trace when an error happens. Currently the stacktrace it shows references only files in node_modules, nothing directly related to the code I’m writing
Hello, anyone who can help me with my question? Thanks in advance. 👇
I never used that combination so unfortunately I can't say. 😞
*Thread Reply:* I was crossing fingers not to get a response like this 😞
I don't use protractor (have in the past, but no longer) but this doesn't strike me as being a cucumberOpts issue
Can you give an example of what stack trace you are receiving and what you are expecting? I do agree with @Cat that I don't believe that to be cucumber related
*Thread Reply:* So in this screenshot, you can see that the section I marked in the yellow rectangle corresponds to node_modules folder.
The rest of it corresponds to a bot I defined. But the flow that goes through the page objects before getting to the bot is not included in the stacktrace. That’s what I’m missing and that’s what I need
*Thread Reply:* I guess I'm a little confused as to what kind of stack trace you want? This stack trace looks correct to me. From bottom-up has the steps to the root of the failure (selenium failure on a wait)
*Thread Reply:* So let’s say I have a login test case. The architecture I have is:
*Thread Reply:* So the stacktrace I’m expecting is for instance, something that includes what’s in the screenshot above, but then the stack continues telling that from step definition on line 3, it went to page object on line 36 and then it went to bot on line 17 and that’s where it crashed
*Thread Reply:* Depends on how your code is referencing the other pieces of the architecture.
Let's switch to a thread so that it's not alerting for the entire channel 🙂
Started digging a bit into Gherkin history and noticed child_process and spawn. Do I have to worry that cucumber will spawn child processes when using it?
Hi @Jonas Amundsen - cucumber-js is still on Gherkin 5 - the Rule keyword was implemented in Gherkin 6
Gherkin 6 (and 7) spawn an executable to do the parsing (it’s written in Go).
We may change this back to a native JavaScript implementation since the spawn executable approach may cause some issues (primarily with virus scanners)
Personally I enjoy and appreciate the ability to inspect node_modules myself and see what I am about to execute
(Which is why I EG. dislike minified builds for modules not intended for the web)
I can understand that. Cucumber has a small team of contributors, and maintaining feature parity in Java/JavaScript/Ruby/Python/.NET/Go/etc is quite a big undertaking.
Cudos to you guys and gals for all the work. Your response time is always impeccable!
Hi! "Guys" is easily replaced with the more gender-neutral "Folks", "All" or "Foolish mortals". We'd appreciate if you tried to use that. Thanks!
Thanks @Jonas Amundsen! We’re still undecided between a) maintaining 6+ biggish implementations and b) moving most code to a shared runtime.
In the short term we’ll probably ditch using a shared go executable runtime for the core of Cucumber. We’ll experiment with some optional report formatters written in go to test our community’s appetite for installing and running code that spawns an executable.
What are your concerns about spawning executables? Spyware? Not knowing what it does?
Orphaned processes in CI machines that aren't very monitored comes to mind
You need to perform signal handling and even then there's edge cases
I guess there's going to be a pipe between the parent and the child, so the child needs to act appropriately when this closes
@Jonas Amundsen - I recently fixed a bug in cucumber-electron for killing sub processes: https://github.com/cucumber/cucumber-electron/pull/31/files#diff-068885e60aad1169ee544e485715e201R97
That stuff can be tricky to get right. Then there's the non-posix compliant systems making it even more difficult
Yeah. We’re also considering using a server/daemon for the shared runtime. Language-specific front-ends would talk to it over TCP
The prototype is here: https://github.com/cucumber/cucumber-engine
The shared runtime (cucumber-engine) does all the gherkin parsing, matching of step definitions and reporting. The language-specific part would be just a thin layer that executes step definitions and talks protobufs with the runtime.
It does increase the internal complexity for sure, but it also means less code to maintain, easier to write a cucumber for a new language, and a consistent behaviour across all platforms.
Have considered parser generators as an alternative to writing N parsers yourselves?
It helped us support multiple languages, but there is still a fair bit of logic to implement by hand in the parser.
Another semi-complex library is the cucumber-expressions engine. We’re maintaining that in Ruby/JavaScript/Go/Java at the moment, and that’s a lot of work. SpecFlow (.NET) doesn’t even have cucumber-expressions, because nobody has bothered porting it to .NET. But if everything just sat in a shared runtime….
So @Jonas Amundsen - if the shared runtime was a daemon process that is started before running Cucumber, and protobuf comms happened over TCP, any thoughts on potential problems with that approach?
When you say daemon, will it be designed to remain running afterwards?
It could be designed to kill itself after N seconds (for CI), or it could stay up indefinitely (for dev machines)
And obviously it could be sent a protobuf message (or SIGKILL) telling it to quit
Good! Our main worry is that people will get upset by having to install a “program” in addition to their npm/gem/jar/whatever. We’ll run an experiment with formatters first to see how well it goes down
Right now Gherkin 6 bundles cross-compiled executables inside the package, but that seems to get stopped by corporate firewalls/virus scanners, so we’ll probably abandon that approach.
I experimented a while ago with an ~/.npmrc that set ignore-scripts=true, which obviously disabled any installers, but also removed what I basically consider to be a remote code execution vulnerability
Maybe we just need to wait until all software in the world is written in one ubiquitous programming language so we don’t need to worry about things like this!
Btw, do you have any insights into whether cucumber-js will be updated to recent gherkin?
I think we need to resurrect the native JavaScript implementation of Gherkin and then add Rule support to it. I deleted it a few months ago and now the gherkin npm package is just a few lines of js delegating to the go executable.
It’s too risky to make a release that relies on those embedded executables.
That sounds like a plan 🙂 Tell me if you need someone to test anything and such
One of my clients has an Angular (TypeScript) app that is already live, but under continuous development. Karma is used for Unit Testing currently and Protractor for everything else - which means their regression suite is growing out of hand. I’d like to shift the tests further left and do some fast acceptance tests in Karma - and try to reduce the I/O like the excellent subsecondtdd. Can anyone help with tips or advice for creating fast acceptance tests in Karma with Cucumber?
Aslak, I'm itching for rules in my cukes - is there anything I can do to help? I can probably do the grunt work in terms of resurrecting the old version from history, and if the berp has already been updated, even write some tests for the new behavior.
Hi @Jonas Amundsen yes you can help! In Gherkin v6 we ripped out most of the Java code and delegated to embedded gherkin executables in Go. We’re abandoning this approach (too risky), and we need to resurrect the native Gherkin JavaScript implementation:
1) Create a new branch from master
2) Add the JavaScript parser code that was deleted prior to v6
3) Port the code to TypeScript (all the JavaScript code was ported to TypeScript recently)
4) Implement support for the Rule keyword
5) Keep the ability to delegate to a Go executable (should be a boolean switch) so we keep the door open in the future.
6) Release Gherkin 8
7) Upgrade Cucumber.js to use Gherkin 8
Yes, master supports rules, but the only parser implementation on master is Go at the moment. Java/JavaScript/Ruby currently spawns the go executable to do the actual parsing. We need to go back to how it was done in v5 - a pure JavaScript implementation.
I’d be happy to help you if you have any questions. And we’ll pay you if you submit expenses to https://opencollective.com/cucumber
Cool, thanks for the write-up. I'll give you a ping when I've made some tangible progress
*Thread Reply:* @Jonas Amundsen for step 2) I recommend you grab the code in gherkin/javascript/lib at tag gherkin-v5.1.0
*Thread Reply:* Don’t forget to ping if you get stuck too! We’re here to help if we can 🙂
*Thread Reply:* Matt, I've posted a PR with some preliminary work if you would like to take a look: https://github.com/cucumber/cucumber/pull/689
*Thread Reply:* Hey @Jonas Amundsen that looks impressive! I will try to review this in the next couple of days. Thanks so much!
Cucumber: v5.1.0 Question: How do you attach a screenshot to the results? Error: world.attach() is not a function
*Thread Reply:* https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/world.md
*Thread Reply:* and more details on attachments: https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/attachments.md
Hi All,
I have a hook like this
Before({ tags: '@deleteInvestigation' }, async () => await createInvestigations(1, Constants.investigationToDelete));
For some reason, that hook runs not only for the scenarios tagged as @deleteInvestigation but for any other scenario as well
*Thread Reply:* You're using an arrow function. It impacts this which is necessary for hooks, steps, and the world instance to operate properly. Change it to async function () {...} and it should work
*Thread Reply:* should get it working, but if it doesn't, lmk and we can dig more 🙂
*Thread Reply:* @Cat interesting. It did work. Why is it that when using arrow functions it doesn’t work as expected?
*Thread Reply:* Hi, it's cukebot again. "Doesn't work" is rather vague. What are you seeing and what had you expected to see?
*Thread Reply:* It has to do with the way arrow functions bind lexical this, which impacts this which is shared between the world, steps, and hooks (as mentioned above).
Hi All,
is there a way to run a hook after all .feature files have run?
*Thread Reply:* I know of AfterAll(), but I’m using protractor which uses webdriver js. And because of the way webdriver js handles things, AfterAll() is triggered after every single .feature file, rather than running after all files have run
*Thread Reply:* Then I would check with protractor folks 🤷 It's going to be distinct from using cucumber itself. It's not actually a webdriver js issue, iirc, but rather that it's a cucumber plugin for protractor, rather than cucumber running protractor 🙂
so I'm not sure but are you looking for a teardown hook? In ruby there exists one called at_exit there could be one for JS I'm not sure.
@Alaeddin select the test run from the dropdown in your icon menu bar and select “Edit Configurations…”
Hey All, so I have a scenario like this: I need to run the same test case for three different users and for each user I need to cover 5 sections
user 1
section 1
section 2
section 3
section 4
section 5
user 2
section 1
section 2
section 3
section 4
section 5
user 3
section 1
section 2
section 3
section 4
section 5
Put your users in your example table, assuming that your "section 1-5" lines are a single scenario?
so have some logic that sets user = user1 - then run the five tests.
Then have the job cycle through three users running all tests.
in ruby some simple pseudo logic would be
[user1, user2, user3].each do |user|
ENV['THING'] = user
Rake::Task['test_to_run'].invoke
end
^ I would handle this outside of the features themselves and pass it as an environment var, as luke has done here. Unless there is specific scenarios for each user, then those would ideally be done as different features.
Imo, it depends on the context. A scenario outline could easily be applied, from the looks of it, but whether or not it's appropriate depends on the relevance of the user params
Hey @Marco Sanabria - I was just reading this back and I wondered if the scenarios you were running for different users were exactly the same? Are any of the behaviours / outcomes different depending on the user?
so, the scenario is something like this: Say I have a web page that has 5 sections, the user is able to add a comment on each section (the 5 sections I listed above). Ok, now we have three different user roles and we wanna make sure that all of the users can post comments on all of the sections
I was wondering id there was something like nested examples tables
I’m interested in this idea of testing the same behaviour multiple times, and whether there’s a better way to get the confidence that your application works as expected.
Can I check that I’ve understood:
So, by testing that capability in all 5 sections for each of the 3 user types we end up with 15 tests of essentially the same thing.
if we follow the same line, that would mean we would end up with 20 tests 🤔
(assuming that the new role has the right to make comments as well)
Let’s assume that adding more and more tests of the same commenting function is something we’d like to avoid.
However, we’re trying to learn something by having those tests, what are we trying to learn?
I mean - we’ve got 15 tests to give us confidence that the app is working correctly:
Let's consider another question: Is it likely that commenting will break for one type of user on one section vs. all sections?
Right! Adding more special cases will just result in needing more tests and if we bundle up each of those different concerns we get a combinatorial explosion of the number of tests we need.
^^ and when we do so, we are increasing the time it takes to run our tests AND decreasing their value
I think what I’d want to do is find those different concerns that we care about and test them individually, probably at a lower level. Then maybe I’d just need one or two integrated tests that give me confidence the whole thing hangs together.
Hi! "Guys" is easily replaced with the more gender-neutral "Folks", "All" or "Foolish mortals". We'd appreciate if you tried to use that. Thanks!
Hopeing to get some help with cucumber and typescript. I've used a data table in a step, when I output this table to the console, the object is a DataTable that looks like:
DataTable {
rawTable: [['xxx'], ['xxx']]
}
I was hoping to strongly type this in my cucumber step, but can't find a matching type in the @types/cucumber library. I was hoping to do something like this:
Then(/^Carl should see$/, async (thingToSee: DataTable) => {
*Thread Reply:* You can use YAML or JSON w/JS - cucumber is for demonstrating behaviors, however. You wouldn't reference the fields the way you're doing here. What precisely are you attempting to do with the data here?
*Thread Reply:* The idea is that product owners can see what is being involved in the tests, as they do not know the code, it would cost them a little more to understand.
*Thread Reply:* Why would you not simply use business language for the data tables?
e.g., I insert <name> in the name field where the data value for name is, say Steve (or whatever value, really)
This would then pass into the stepDef function, which you then would tie to datosPrueba.comment
Hi, does anyone have here any experience or can recommend documentation around mocking out API calls. We use a couple of different API's in our angular webapp and it's been a pain handling this since from what I can tell, using protractor-cucumber js, it doesn't allow to inject the mocks so we have to use the actual objects. Currently we are using HMR to achieve a mock client but so far has proven to be very messy. I know that protractor is made for e2e testing, so ideally the test would hit the API, but we want a controlled environment to be able to run our cukes. Our plan of attack is to add a mock server that we can pass our given's to so that the server can respond accordingly but wasn't sure if there was a better way to handle that.
*Thread Reply:* Hi @Ryan Kazokas we use Angulars own In memory api tool, its very extensible and has covered all our requirements so far.
I've hooked in an environment variable so that we can flick from using the mocked api to the real ones while developing.
John Papa uses it in the tour of heros demo, I've taken that and build cucumber into it in this repo as a proof of concept: https://github.com/DesHorsley/angular-tour-of-heroes
*Thread Reply:* Awesome, thanks for the advice! I will definitely take a look at this!
*Thread Reply:* @Des Horsley Almost thought we'd be able to use this, but we can't since we have an SDK that is using axios and is not using httpclient to make the requests. From what i can tell it will only work with the http and httpclient
is there not a fixtures and fittings npm package you can use? I know there are plenty in java and ruby
*Thread Reply:* I was unable to find anything that would aid in this outside of running an actual mock server, b ut this has it's limitations, mainly running tests in parallel is the main concern with that
*Thread Reply:* Agreed. I know java has good support as I use cucumber there, but i think the main problem is that unlike junit, protractor isn't really made for mocking/stubbing but more for browser automation.
Heyo! I have a few questions and would appreciate if someone could shine some light on them. I am on v5.1.0 and using TS in my project.
1) As per doc on git: Use --tags <EXPRESSION> to run specific features or scenarios
Passing a single tag @smoke works just fine, but if you are passing multiple tags as per <EXPRESSION> format using and, or it throws Error: ENOENT: no such file or directory, open:'...'
Example call: cucumber-js --tags @smoke or @test
2) Is there a way to pass custom CLI options to the child processes spawned with --parallel? I am able to manually parse additional options which I provide after: cucumber-js --tags @smoke -- --customFlag and it works for non parallel runs. Or perhaps - is there a better way to do this, extend cucumberjs CLI somehow?
3) Perhaps I am not the brightest crayon in the pack - but how exactly can you listen to events emitted?(scenario, step, test run ended or whatever events there are) I didn't see anything in the docs that would help. Browsing on the web - there seem to be various mentions of it, but it is mostly for older Cuke versions.
Good afternoon. I am trying to run Chrome in headless mode. My world.js looks like this:
https://developers.google.com/web/updates/2017/04/headless-chrome
This is my world.js In package.json I have "chromedriver" "76.0.0" I've downloaded the appropriate chomedriver version for windows. I've checked my path in environment variables. But the session still does not run headless. Any suggestions? And thanks @Gem, I will read the link you provided.
*Thread Reply:* Was able to get this working again this morning by following https://intoli.com/blog/running-selenium-with-headless-chrome/ which was referenced in the link @Gem provided. I inherited this project, so I deleted all the previous chrome setup and replaced with this much simpler version
So, I'm trying to match When I press "foo" -> "bar" -> "baz", but the following expression /^I press "([^"]+)"(?: -> "([^"]+)")**/ doesn't work because all but the last captured optional group is retained, as shown below
$ node
> 'I press "foo" -> "bar" -> "baz" -> "qux"'.match(/^I press "([^"]+)"(?: -> "([^"]+)")**/)
[ 'I press "foo" -> "bar" -> "baz" -> "qux"',
'foo',
'qux',
index: 0,
input: 'I press "foo" -> "bar" -> "baz" -> "qux"',
groups: undefined ]
Hi, it's cukebot again. "Doesn't work" is rather vague. What are you seeing and what had you expected to see?
Is this just the way it is and should I then parse the series with code?
And with doesn't work I mean that buttonTexts in When(expression, (...buttonTexts) => ...); aren't populated with all matching button texts
Hi, it's cukebot again. "Doesn't work" is rather vague. What are you seeing and what had you expected to see?
@Jonas Amundsen do you have a variable number of -> in your steps?
That is indeed the idea! Per now I've solved it by matching all the quoted names separated by -> and parsing them with code
I realize now that this might be a restriction of Regexp.match more than it is of Cucumber
@Jonas Amundsen have you considered defining a custom parameter type? https://cucumber.io/docs/cucumber/cucumber-expressions/#custom-parameter-types
Ahh, that sounds a lot like something I want. I never thought about that, thanks! 😄
Hi folks! I have made this question in general help channel and I don't get answer, so may be here I can get any idea to solve my use case. I'm working with protractor with cucumber, so I want to fill the data table content with values that are contained in a JSON file, the reason to do that is because depending of a protactor comand argument these values have to change (f.e. protractor sanity.config.js --param.a have to make login test with user: demo1 password: 1234 and protractor sanitiy.config.js --param.b have to make login test with user: demo2 password: 5678, for a few use case I know I can duplicate the feature but in case the data comes bigger I think the most usefull is read data table content from json values depending on the parameter, is this possible? Any workaround to solve this use case? Basically I want to use different data table examples depending a on input parameter
off the top of my head, you'd need to write something to parse the json, then potentially create an outline from the values?
@Amanda R We have https://cucumber.io/docs/guides/10-minute-tutorial/ which tells you how to get started with a project, or https://cucumber.io/docs/installation/javascript/ which tells you how to install it. Do either of those help you?
*Thread Reply:* @mlvandijk thanks I've seen those but I was looking more for a tutorial to code along with to learn.
*Thread Reply:* What do you want to learn? There's also Cucumber School if you want a course on BDD / Cucumber.
*Thread Reply:* I was trying to find tutorials with BDD and JS, that site only has Java or Ruby
Hey, folks Just noticed that the new version of cucumber doesn't work with cucumber-pretty module. need to update the cucumber-pretty module based on the latest event protocol methods. https://github.com/kozhevnikov/cucumber-pretty/issues/10
Are doc strings compatible with templates? IE. can I write scenario outlines like following
Scenario Outline: foo
Then foo
"""
<bar>
"""
Examples:
| bar |
| 1 |
| 2 |
| 3 |
*Thread Reply:* @Jonas Amundsen yes you should be able to. If not it’s a bug 🙂
I'll have a quick check on cucumber rails because we have a bunch of docstring tests.
I amended one test from cucumber-rails like the following (Apologies it's long winded)
Feature: No Database
Allow Cucumber to work with a Rails app without a database
Scenario Outline: No ActiveRecord and DatabaseCleaner
Given I have created a new Rails app with no database and installed cucumber-rails
# Turn off ActiveRecord
When I write to "config/application.rb" with:
"""
require File.expand_path('../boot', __FILE__)
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'rails/test_unit/railtie'
Bundler.require(:default, Rails.env) if defined?(Bundler)
module TestApp
class Application < Rails::Application
config.encoding = 'utf-8'
config.filter_parameters += [:password]
end
end
"""
And I overwrite "features/support/env.rb" with:
"""
require 'cucumber/rails'
"""
And I remove the 'database_cleaner' gem from the Gemfile
And I remove the 'sqlite' gem from the Gemfile
And I write to "app/controllers/posts_controller.rb" with:
"""
class PostsController < ApplicationController
def index
raise 'There is an error in index'
end
end
"""
And I write to "config/routes.rb" with:
"""
TestApp::Application.routes.draw do
resources :posts
end
"""
And I write to "features/posts.feature" with:
"""
Feature: posts
Scenario: See them
When I view the <test_one>
"""
And I write to "features/step_definitions/posts_steps.rb" with:
"""
When('I view the posts') do
visit '/posts'
end
"""
And I run `bundle exec rake cucumber`
Then it should fail with:
"""
There is an error in index
"""
Examples:
| test_one |
| posts |
Important bit is
And I write to "features/posts.feature" with:
"""
Feature: posts
Scenario: See them
When I view the <test_one>
"""
Cool! The reason I'm wondering is because I was surprised to see it wasn't working with cypress-cucumber-preprocessor. This is a somewhat interesting tool, because it integrates Cucumber with Cypress, where the latter provides its own test constructs (describe, it, etc.). Hence, the tool must traverse the AST by itself and re-implement some of this logic.
@Jonas Amundsen it uses gherkin 5 (https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/bfdb5af466a2853937ecd2b209eb6129a79caeb9/package.json#L54), which might have a bug with this. I can’t find any mention of fixing this bug in the changelog (https://github.com/cucumber/cucumber/blob/master/gherkin/CHANGELOG.md) - if it was ever reported. Maybe the bug is still there, IDK.
Does gherkin handle replacement though? The tool (cypress-cucumber-preprocessor) performs replacement by itself, as seen here [1] and here [2]
[1] https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/v1.16.2/lib/createTestFromScenario.js#L10-L14 [2] https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/v1.16.2/lib/createTestFromScenario.js#L109-L117
The bug has been fixed:
It was fixed here: https://github.com/cucumber/cucumber/commit/ec7a9ebd2b9238c94c1d1307751350554b37c08f
Ah, so the outputted pickles doesn't contain outlines, but expanded scenarioes where this is replaced?
PR: https://github.com/cucumber/cucumber/pull/292 - released in 5.1.0, which is what cypress-cucumber-preprocessor is using.
So if it’s not working they have implemented their own broken logic rather than using the pickle compiler that comes with gherkin.
I fully expect that I'll be doing the upgrade, as this tool is rather unmaintained
But in other words, it seems like this will get a bit easier with the most recent version of Gherkin
Do you know which gherkin 5 though? It could be that they're "just" behind on it?
Fail-safe check. try on gherkin 6. Before ruling this out
@luke they are on gherkin 5.1.0 - https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/bfdb5af466a2853937ecd2b209eb6129a79caeb9/package.json#L54
I don’t recommend gherkin 6 because of all that embedded go executable jazz. Gherkin 8 is better!
Any idea when cucumber (npm) will update its dependency on gherkin?
Hard to say - nobody has started work on upgrading it to Gherkin8 AFAIK. My focus at the moment is to do the same for Cucumber-JVM.
*Thread Reply:* I'm not seeing --require anywhere. How are you telling cucumber where the step definitions are?
*Thread Reply:* because it looks like it's just passing the formatter params
*Thread Reply:* I am using tags to identify the features in which to run, but even still, when I run npm test, it should run the entire suite
*Thread Reply:* ok. let me rephrase that.
in your package.json, how is npm test defined?
*Thread Reply:* Right. that is just telling cucumber the reporter you want to use. It's not telling it where the support code is.
*Thread Reply:* https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md
*Thread Reply:* yeh most of them you need to provide the location of step defs. I know some of the flavours have autoloaders if you put the steps in a certain place.
can anyone here help me get a very basic (i mean STUPIDLY BASIC), example of cucumber and js working with browser automation>
I was trying to get it working with a POM package, but I'll take just working against google.co.uk atm.
*Thread Reply:* i'll use whatever really. I just want something where i can do basic browser automation.
*Thread Reply:* we'll move on from that once i lose the training wheels. The problem I have is I only really understand ruby.
*Thread Reply:* I could throw a quick GH example up for you but realistically prob won't get time until later this evening (EST)
*Thread Reply:* that's fine. I tried wdio, I couldn't get it to work. I tried wdio (both selenium and non-selenium), i tried raw selenium (worked best but had some issues), cypress (not great), and all of them I couldn't reliably get to run.
I'm fairly certain I'm the issue here.
*Thread Reply:* Nah, config + getting started is, hands down, the hardest shit 😄
*Thread Reply:* Kind of. Literally all i'm looking for is a sample to do page object model testing with js. The problem I have is it feels like the config files in js are 100s of lines compared to ruby which has 5-10 lines.
*Thread Reply:* https://github.com/site-prism/site_prism/blob/master/features/support/env.rb
That's the config file for site_prism (And some of that isn't needed for regular testing, its because its using travis)
*Thread Reply:* as someone who went from Java/Groovy/Lisp code base to Javascript/Golang codebase: Forget everything you know about any other language before you proceed 😂
*Thread Reply:* if I can get a directory that has 1 feature, that loads up google and does a search and validates the results that would be epic. I know it sounds silly but I'm genuinely struggling to do that. But I know it's me that's the issue.
*Thread Reply:* Think lisp is similar to ruby in some aspects, or at least thats what matz (the creator), said.
*Thread Reply:* no no, it's not you - even for experienced JS devs, getting configured and moving with browser automation is difficult
*Thread Reply:* im leaving work soon and won't be back until wednesday and plan on having a break. So don't sweat it.
If you can give me some pointers epic. But don't stress yourself too much.
*Thread Reply:* no biggie! let me see if I can whip up just a basic config + cucumber + wdio example for you so you can see the gist of it
*Thread Reply:* take your time, but yes please feel free to help.
I try and do the same with ruby, but sadly it's getting less popular 😞
*Thread Reply:* @luke did you ever get anything to work? im in the similar boat with JS and trying to learn
*Thread Reply:* I'm at work right now, but can whip up something pretty quickly once I get some free time (which I hear is a real thing, in spite of it being slightly mythological in my own personal life)
*Thread Reply:* i haven't been able to get anything to work except cypress, so...i feel dumb about it all
*Thread Reply:* I tried nightwatch, but it kinda isn't right. Because it wasn't quite doing proper browser automation.
*Thread Reply:* well it is fine, it's just I found the configurability a bit too coupled. Frankly I don't care how I write the tests, so long as I can write some and maybe learn by doing it.
*Thread Reply:* @Amanda R you said you couldn't get anything to work in cypress - could you elaborate?
*Thread Reply:* yeah @Cat Cypress is the only thing i can get up and running
*Thread Reply:* ive tried webdriverio and also nightwatch without any luck
*Thread Reply:* ive worked with selenium at a past company but never had to deal with project set-ups
*Thread Reply:* my recommendation:
Start with cucumber. get it set up doing a basic scenario sans any other configs (e.g., get some steps like Given 2 / When I add 2 / Then I get 4)
*Thread Reply:* Once you get that done, start with a very basic config to start your driver
I'm onto my 5th spike of different software combinations and I'm getting kinda pissed.
well im trying to just get any sort of browser automation working with js, but I've tried so many different frameworks and they're all too confusing for me or they don't let me customise stuff. I think my lack of knowledge is biting me in the rear here.
So you’re using Cucumber.js? I got confused since you mentioned POM (which is Java)
I'm sorta half trying to find something easy, because I need to learn js whilst doing it.
Is anyone configures ALLURE REPORT with Espresso plus BDD (Cucumber) Framework in Android Studio...? or Suggest any other Reporting Tool supported by Espresso with BDD (Cucumber) Framework...
I have another question about the behavior of cucumber.js and if cypress-cucumber-preprocessor diverges from it. In cucumber.js, if you define a step using eg. When("I press button"), can you invoke it from a feature file using Given I press button?
Notice it's not worded according to (my) expectations. Will the framework enforce it or are the types transparent?
It will work. Cucumber is agnostic of the step keyword. This is by design.
I see. I'm currently observing that the language of our tests is somewhat deteriorating when not every change is strictly reviewed. I appreciate quick feedback (hence I test) and strictness in tooling, hence I also naturally dislike ambiguity. What if types were taken into considering, but steps matching multiple registered definitions yielded a runtime error?
And having the runtime error not take type into consideration, thus retaining the property of unambiguous language
We don’t want to allow the definition of two step definitions meaning different things. For example:
• Given(“I press button”) • When(“I press button”)
By allowing this, we’re also allowing ambiguous language to creep in
I'm totally with you and I mean that one can validate this during runtime. If a step matches a definition residing in the Then-registry as well as the Given-registry, then that can be considered an error
Just as I would consider a step matching multiple definitions an error today (albeit cypress-cucumber-preprocessor doesn't enforce that, it merely selects and invokes the 1st matching definition)
There is no Given registry or When registry. There is just stepdef registry. Are you suggesting we have different registries so that Given("I press button") cannot be used in a When - and that we don’t allow the same expression to be used across registries? I think that would be nice.
It shouldn’t be that hard to implement. We can still use just a single registry, but use a compound key for lookup (both the keyword and the gherkin step text).
Given that the gherkin reference itself specifically stipulates different behavior, then I guess this suggestion affects not only cucumber.js, but all implementations?
Yes indeed. And here is a proposal for how we can better keep track of features that should be ported around: https://github.com/cucumber/repo-template/issues/4
Hmm, interesting. The behavior discussed here is about how a consumer of Gherkin treat the output. Cucumber.js might change to depend upon 8.x.x, but not yet exhibit these attributes. Do you think of this as a contract and that a change in it warrants a bump in Gherkin version, even if the change in Gherkin is merely in the documentation?
Gherkin just produces an AST (and pickles, which is a simplified representation) - it doesn’t interpret anything. So if we want to change semantics of how keywords and step definitions work, that’s a change in Cucumber
Alright, but the behavior suggested here is surely a backward-incompatible change. And it seems that "varieties" describes "some feature set" that a developer can count on by grouping versions, but the cucumber version numbers are independent across implementations, right?
So it seems like varieties doesn't allow for describing this, as long as it's only a version tuple of the dependencies
Varieties (or milestones as we might end up calling them) define any behaviour. It can be dependency on a particular library version (gherkin 8.1), or it could be a feature (must have a protobuf formatter). In this case, must distinguish between GWT in stepdefs - with a link to an issue describing it in more detail.
I've tried to outline the above-mentioned proposal here btw: https://github.com/cucumber/cucumber/issues/768
Between retries, the default World is not getting cleared. Is this expected?
It's me again, the cypress guy. So, the way cypress-cucumber-preprocessor works today is that it transforms the feature-file by parsing it using the old, native parser, and returns a template containing the AST [1], which uses Cypress' own test-constructors [2] (describe & it - from Mocha) to create tests. Since it works on the AST, it needs to re-implement EG. the expansion logic of scenario outlines. Consuming pickles would remove the need for re-implementing that specifically, but the pickles themselves doesn't contain the necessary information to re-construct the hierarchy of describe() and it() blocks. Any of you have any suggestions as how to best integrate these tools?
[1] https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/v1.16.2/lib/loader.js#L16-L19 [2] https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/blob/v1.16.2/lib/createTestFromScenario.js#L37-L51
Good afternoon. I was handed an existing cucumber-js/selenium webdriver-js project to take over and I am unable to get driver.close() and driver.quit() to work on either Windows or Ubuntu on my local machine. They are located in world.js in the AfterAll hook. When executing the project in VS Code it leaves chrome.exe behind and on Ubuntu/Linux it leaves chrome files behind. I've tried different chrome options as well to no avail. In ubuntu, chromium-browser --version = "Chromium 77.0.3865.90 Built on Ubuntu , running on Ubuntu 18.04" and chromedriver --version: "not found" (however chromedriver is a dependency in package.json). I'm not sure why the setWorldContructor uses CustomWorld.bind(undefined, driver) as I haven't found any examples with this. I notice also that in my project in stepDefs.js another webdriver is created. I've included package.json dependencies, world.js, and the beginning of the stepDefs.js file in my project. Appreciate any help in advance.
Good morning. Please read previous message regarding driver.quit() not working. Thank you.
I see you’re catching any error there
AfterAll(function() {
try {
driver.close()
driver.quit()
} catch (error) {
console.log('ERROR TRYING TO Quit' + error)
}
})
is the runtime falling into that catch? If so, that would a good start to figure out what is going on
How can I specify the path to the chromedriver.exe in the project? Can I do that in the world.js or a package.json script? (Besides using windows PATH environment variable.
you can use chromedriver package from npm https://www.npmjs.com/package/chromedriver
you can see in the doc that when installing it, you can either force it to download it or specify the path
after that, you don’t have to specify the path anywhere in your code
@Marco Sanabria Wow. I've spent almost a full day on this. And as usual, such a simple fix. Made the function in the AfterAll hook async and then added 'await' to driver.close. Voila. That's the fun part of taking over stuff...learning all the nuances. Thanks for you help!
Gurus of Cucumber-js, I salute you. 🙂 Does someone have knowledge if cucumber-js is feasible to use with React Native (especially with Expo)? Is there some tutorial, that shows it with real examples? Or do you know some OSS project that uses cucumber-js in a way that can be studied to learn it's ways? I'm struggling with documentation alone to grasp this. And yes, I know that Jest is good... however I hope to get benefits of Gherkin syntax, and BDD, and I feel Jest sits nicely in TDD. I've struggled with this several days, but for some reason my brain just don't wrap around this. Any kind help guiding me forward, or even making confident statement that "No, you should not try to use cucumber-js with RN/Expo, it is waste of time", it would ease my mind and let me continue to next topic to learn & try out. 🙂
I’ve created an issue here @kerbe: https://github.com/cucumber/cucumber/issues/807
That would be great addition, and definitely make it easier to start. Or it might surface problems which need addressing too, if there are compatibility problems. 🙂
noticed also @matt-SmartBear's tweet. I will gladly help getting such tutorial done, with my limited knowledge. At least I can be good test subject, does it cover right things in understandable way. 🙂
@kerbe I haven’t done any React Native coding yet. Am I right that you can use Node.js as a development environment with it?
Yeah looks like it. So my understanding is that you can bootstrap an app with the expo-cli npm package. After bootstrapping I’d suggest building a tiny app with a button. When pressed, a counter is incremented. It would be TDD’ed with Cucumber.js
Yes, you are correct. expo-cli init is used to create project. I have then tried adding npm i cucumber, and created features/step_definitions folders. When I make simple feature file, run cucumber with ./node_modules/.bin/cucumber-jsI get steps to be added to steps file. Doing those, I get into point what is expected, having pending steps. But from here on I'm lost. How do I connect "right way" my RN code to these step files? If i try to import, I get error:
SyntaxError: Cannot use import statement outside a module
And here my understanding of docs/tutorials fade away, and I would like to see what I should do at this point.
It might, or might not matter that I use Windows 10 Pro. However my development environment is within WSL, as I like to operate under Linux. For some things this can cause problems, but shouldn't matter yet at that point.
@kerbe if you want to push some code to a repo I’d gladly take a look
Alright, I'll see if I get to do that this evening, tomorrow at day at latest. I'm just heading for meetings in few minutes for rest of the day.
basicly steps file has this:
const assert = require('assert');
const { Given, When, Then } = require('cucumber');
import App from '../../App';
And that import gives syntaxerror. Code is otherwise I think from 10 minute tutorial.
And also tried if something like const App = require('../../App'); would work, but then it gives error from import that is inside App.js
@kerbe did you try to replace import with require ? In general, a codebase should settle on one or the other. Using import may require extra tooling to make the import syntax work. If you’re unfamiliar with this, I suggest you just use require
I'm looking into what it would take to upgrade the gherkin-dependency in cucumber-js. At once I notice that generateEvents of gherkin-5 (ref. https://github.com/cucumber/cucumber/blob/gherkin/v5.2.0/gherkin/javascript/lib/gherkin/generate_events.js) resembles the messages generated by latest gherkin, except that they don't have a type property, but rather an inner object. Would you expect the update of the dependency to be a backward-incompatible change for all formatters or do you think we should try to retain the format of all events emitted?
Hi @Jonas Amundsen. Upgrading to the latest Gherkin in Cucumber.js is a backwards-incompatible change:
• The Gherkin API has changed (method signatures, and more importantly, the use of protobuf objects)
• The AST structure has changes (it’s now based on protobuf, but more importantly, there is a new Rule keyword / AST node)
We’re in the process of re-implementing the formatters in the monorepo (outside cucumber.js). These new formatters will read cucumber messages (protobuf) as input.
Some of these new formatters (like the HTML one https://github.com/cucumber/cucumber/tree/master/html-formatter) are intended to work with any cucumber implementation, and must be installed separately.
Others (such as the pretty formatter, which users will expect to be available to cucumber without having to download a separate executable) will still have to be imlemented natively in TypeScript/Java/Ruby/C# etc, but because they are in the monorepo, we can use a shared set of tests for them to ensure they behave consistently.
I see. Is there any reason to not attempt the upgrade, including the native formatters, other than that they will be changed further in the near future?
It seems pretty straight forward given the current failing tests I'm looking at, so if no, I'll give it a shot
@charlierudolph, are you already working on this btw? Ref. https://github.com/cucumber/cucumber/pull/814
Looks like using requireinstead of importdoesn't make difference in React Native case.
I created simple repo with freshly initialized react native project with expo-cli @Aslak Hellesøy, it can be found here: https://github.com/kerbe/rn-cucumber
It is in working state, meaning if you clone and npm install, you should be able to run npm test and get a start. However, this is point where right way is lost for me... That App.jshas that View and Text elements, and I would like to test that those exists. But if I try to require/import App.js to features/stepdefinitions/mainscreen.feature, I get errors, and I'm lost.
And I think it was also @matt-SmartBear who I was supposed to ping... so some basic code is in the repo, check message above 🙂
appreciated. 🙂 I had surprisingly busy week too, so this took longer than I first thought.
Have you had any luck looking into react native (expo) / cucumber problem of mine?
Has anyone used the Screenplay Pattern? I have a feeling it would clean up my test code, but it seems intimidating to implement, since I can't use the only JS implementation I'm aware of, Serenity/JS.
*Thread Reply:* We have been trying to distill what we learned into Feynman: https://github.com/cucumber-ltd/feynman
*Thread Reply:* I don’t know if it has enough docs yet, or how usable it is for people who didn’t work on it yet, but feel free to have a poke around.
*Thread Reply:* @Jon Beller I’m writing a blog post series about it.
*Thread Reply:* https://cucumber.io/blog/bdd/understandin-screenplay-(part-1)-fundamentals/
*Thread Reply:* What’s stopping you from using Serenity, out of interest?
*Thread Reply:* I may have this wrong, but it looks like Serenity would be difficult to incorporate into my existing test suite that tests an electron app using Spectron, since it has Protractor baked in.
*Thread Reply:* Honestly, you can build your own screenplay framework in a few lines of code.
*Thread Reply:* See here for an example: https://github.com/mattwynne/screenplay-example/blob/b31cf1b3731b63a6d0da5c8912888f7823052749/features/step_definitions/steps.js
*Thread Reply:* Again, please ask me anything: I’m working on these series of article for someone just like you, so it would be really helpful to me to understand more about your context, what questions you have etc.
*Thread Reply:* @matt-SmartBear this is really exciting, I've been using blue harvest with Angular and its worked out well, but it looks like the project is no longer supported. Its been working well with cucumber, but still needs love. I'm glad to see that work is being done on an alternative.
*Thread Reply:* https://github.com/angular-seattle/blue-harvest
*Thread Reply:* In this example, what is on this.abilities? It looks like name and app. Why do we treat those as "abilities"?
*Thread Reply:* OK @Jon Beller so in the screenplay metaphor, the abilities are “things the actor is able to do”. In this example, the actor has the ability to:
• recall their own name
• make calls to the app’s JavaScript API
Other abilities you might want to pass to the actor are things like a browser or a databaseConnection
*Thread Reply:* I have a concern that the Tasks aspects of the pattern would make our tests harder to debug compared to putting procedural logic directly in step definitions.
With procedural logic you can step through line by line with the debugger. In screenplay, your interactions execute in a loop inside attemptsTo, and then are hidden under layers of Tasks you'd have to step into and back out of.
Have you found this to be an issue?
*Thread Reply:* I'm also concerned it will be tempting to shove one-off scenario-specific logic or conditionals into Tasks, making it difficult to reuse them, or to know what you're breaking if you modify them.
*Thread Reply:* re. debugging, to be honest I haven’t notice that to be much of an issue, no. Would it not be possible, depending on where you put your attemptsTo function (you could use https://github.com/cucumber-ltd/feynman/) to have your debugger step over the infrastructure and stay in your task functions?
*Thread Reply:* I think it’s generally OK to have quite scenario-specific one-off tasks. What I see happen is that those tasks tend to get decomposed into smaller re-usable pieces, either tasks or actions. The smaller those pieces are, the less likely it is that you’ll want to modify them in future, so there’s less risk of that “what will I break if I change this” problem, I think.
*Thread Reply:* I might be good to talk about a specific example here. Do you have one?
Happy new decade everyone! 🙂 @matt-SmartBear have you had chance to look into React Native (Expo) & Cucumber-js problem I had last year?
*Thread Reply:* If you look this channel upwards, in beginning of December, might be easiest reminder?
*Thread Reply:* https://cucumberbdd.slack.com/archives/C6QJ6N695/p1575470121133000 << like that was last time it was talked about
*Thread Reply:* And original problem was this: https://cucumberbdd.slack.com/archives/C6QJ6N695/p1574794814100000
*Thread Reply:* It relates also to this issue: https://github.com/cucumber/cucumber/issues/807 as hopefully result of my problem is solving that issue, ie. providing good example how cucumber-js is used with react native.
does anyone knows if there is a plugin for cucumber-js that allows me to get code coverage for an react-app?
I believe https://github.com/istanbuljs/nyc would work
*Thread Reply:* thanks, but I was hoping for something else. I already tried it with jest which include nyc, but I will give it another try with mocha
*Thread Reply:* Hmm why did it not work? I don't think there should be a difference between jest and mocha in this case I haven't run it with jest but I did run it with Mocha and it worked, heres an example of the script I ran
"test:coverage:cucumber": "nyc --nycrc-path=spec/unit/.nycrc-v1.json npm run cucumber:regression"
• test:coverage:cucumber - What I named my npm script
• nyc --nycrc-path=spec/unit/.nycrc-v1.json - Calling Istanbul and the profile
• npm run cucumber:regression - My cucumber tests
*Thread Reply:* sorry I should clarified what my issue really is. I am trying to integrate cucumber js for my bdd testing. I was able to do that with a simple create-react-app typescript template. I am trying to achieve two things here. 1) create a json report for my bdd feature files (was able to do that) 2) create a code coverage report(inprogress of figuring it out). I know jest can give me a code coverage report, but it doesn’t integrate well with cucumber-js
*Thread Reply:* I guess I don't understand, what you are saying. If you have cucumber working and test running then you just need to create an istanbul profile of what code you want it to look at and what level of reporting. Then you just call your test run with nyc
nyc *nyc-profile* *process to run*
In this case the process to run is your test suite ^ that could be jest, mocha, cucumber etc
*Thread Reply:* thanks I think I figure out what you are saying. Sorry I am still new to testing. Thank you for guiding me through this.
*Thread Reply:* No problem, feel free to ping here again if you have more questions
*Thread Reply:* @Vu could you share how you have setup your cucumber-js + react native? I tried doing similar with expo, but didn't get easily cucumber-js working. Your setup steps could give me necessary direction what to do, so I'll get forward too. 🙂
*Thread Reply:* @kerbe I didn’t used react native, but react. All I did was install cucumber and set the script in my package.json.
*Thread Reply:* Ah, my mistake. I somehow managed to read / understand that you had used react native. 🙂
*Thread Reply:* yeah sorry I never used react-native, I don’t know how big of a difference between the react and react-native configuration
*Thread Reply:* Too big for cucumber-js to "just work" like it does with react. 🙂 As I haven't used that much of react, seeing talk about Jest equalled in my head that it is react native project. 😄
*Thread Reply:* create-react-app script used jest as their default test-runner. I just simply replace with cucumber-js
*Thread Reply:* Did the coverage work? Also you shouldn't need ./node_modules/.bin in your scripts as npm knows to look in there for commands, and they default to using the local libraries
Hi! "Guys" is easily replaced with the more gender-neutral "Folks", "All" or "Foolish mortals". We'd appreciate if you tried to use that. Thanks!
@Viktar Silakou scenario.name will return the scenario name object. For other methods just operate on the scenario object.
As I said, just check what methods are exposed on the scenario object.
for ruby you have the following
(scenario.methods - Object.methods).sort
=> [:__getobj__, :__setobj__, :accept_hook?, :all_locations, :all_source, :around_hooks, :describe_source_to, :describe_to, :exception, :failed?, :feature, :keyword, :language, :location, :marshal_dump, :marshal_load, :match_locations?, :match_name?, :match_tags?, :method_missing, :outline?, :passed?, :source, :source_tag_names, :status, :step_count, :tags, :test_steps, :with_around_hooks, :with_result, :with_steps]
right, but what I've just said is. If you check what methods are exposed on the scenario object in the hook, that will tell you all you need to know.
ssuming the api is setup in the same way. But I've not used the js implementation much sadly sorry.
those docs are more of a holistic view of how to view something. I would look into the npm package (Again I'm not a JS user so I can't be much help).
If you think that kind of info should live in the docs, edit the page and make an addition it would be most useful.
Thank’s i will try it, currently i use wdio hooks for this purpose
Has @matt-SmartBear or @Aslak Hellesøy had chance to check my problem yet? Reminder, it's getting cucumber-js to work with React Native, specifically with Expo. Basic repo for problem: https://github.com/kerbe/rn-cucumber
Hi all, I was hoping to get parallel tests running in cucumberjs, I'm running cucumber on an angular project, is this possible at the moment?
I've found the documentation on parallel builds here: https://cucumber.io/docs/guides/parallel-execution/
But there is no js guide.
*Thread Reply:* Highly recommend the cucumber-js specific docs: https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#parallel-experimental
*Thread Reply:* (ignore the first link, we were debating how to dress for a work event)
*Thread Reply:* Thanks @Cat I had come across that. I'm not sure how to translate that into my protractor setup, my undstanding is that angular kicks it all off under the hood.
I've updated my cucumberOpts in protractor.conf.js to include the following (Just to cover my bases):
PARALLEL: true,
TOTAL_SLAVES: '10',
parallel: true,
total_slaves: '10',
format: [
'json:reports/e2e-reports/results.json'
]
If I don't pass in the total slaves as a string I get an error about an unexpected path.
Running the tests with the above code doesn't seem to provide any time advantage, or produce multiple outputs which I thought would happen (One for each process?)
Any thoughts?
*Thread Reply:* ahhhh, if you're kicking it off with the protractor runner you will want to specifically look at the protractor docs. It may or may not be supported.
Hi there. Long time Cucumber user but I'm looking to use it for something a bit unique. I am wondering if I can call an internal function (maybe with Gherkin) to get an array of all scenarios which would be run in the current configuration (taking tags into account).
*Thread Reply:* Thank you for responding. I'm using Protractor and Cucumber together and it seems really difficult to parallelize tests with that combination. My idea is to gather the list of scenarios which will be run, split them up evenly, create several cucumber "rerun" files, and then run my tests using the cucumberOpts.rerun option. This way I can parallelize them evenly instead of just using shardTestFiles which breaks the tests up by feature file.
@Yehuda Miller haven’t tested but you might be able to:
• use the —dry-run flag to stop the steps running for real • write a custom formatter to build your array of scenarios https://github.com/cucumber/cucumber-js/blob/master/docs/custom_formatters.md
Would be interested to hear the motivation for this
Hi friends! Hopefully a simple question: How do I hover an element? Our navbar requires hovering to activate a dropdown
*Thread Reply:* This isn't a cucumber question. This depends entirely on what you're using as a driver.
*Thread Reply:* Our steps are written in gherkin. Does that help? Sorry, I'm very new to this system.
*Thread Reply:* This sounds like a question about Selenium WebDriver @Adam - they have their own community
*Thread Reply:* Thanks. There's so little documentation with this system we're using that I'm having to run in circles to get any information.
*Thread Reply:* If it's in js, you can look at the package.json to see what dependencies are being leveraged
*Thread Reply:* @Adam Cucumber runs the tests for you (and reports the results), but something will be being called from the javascript code in those tests that is automating the browser. Could be selenium but could be something else too. What kind of app is it you’re testing?
@Jean-Philippe Poulin de Courval has joined the channel
Is there a timeline for publishing latest changes, particularly the updated dependency on gherkin? 🙂
as we're an open source project it'll get done when it's done. I know it's one of the items people are working on a lot, but gherkin has gone through a couple of major revisions recently. So it's just going to take some time.
*Thread Reply:* I totally get that and I didn't mean to imply anything. "No" is a perfectably acceptable answer here.
Does anyone here use cypress and cucumber. I think I've found a good guide to get a basic sample setup working, but I'm not 100% on bits of it.
*Thread Reply:* to use cypress with cucumber, you have to use a pre-processor. We opted to simply not use cypress with our cucumber implementation, honestly. It wasn't worth the hassle.
*Thread Reply:* I've got some sample project here: https://medium.com/@itortv/how-to-integrate-cypress-and-cucumber-in-your-development-flow-in-just-a-few-weeks-96a46ac9165a which seems simple enough.
I'm still struggling to get something that combines the 2 aspects I previously had which both worked.
A seleniumJS raw script which I could pause and debug. And proper tests written with POM and classes / functions e.t.c.
*Thread Reply:* I have this project that does POM: https://github.com/healthbridgeltd/ui-tests-boilerplate
*Thread Reply:* I'll take a look at that @Ayethin - I think one thing I really need is just a mini-sitdown session to get it working the way I can get stuff working in ruby, So debuggable / viewable e.t.c.
*Thread Reply:* yeah, that is slightly out of date, but should hopefully help
*Thread Reply:* I'm struggling to get cypress to pause during execution in my code in RubyMine - Raw Selenium works, so it's either something simple I'm doing wrong or some misunderstanding I have.
*Thread Reply:* you can pause with .debug() or just from the browser itself with the built in debugger if that is what you are after. Outside of that I don't know any way
*Thread Reply:* neither are working properly. Because I'm still a newbie. I think I've got this project 75% working. There was some bugs in the selectors.
*Thread Reply:* Big issues I've got atm.
Output response Speed Config debugging
*Thread Reply:* to my knowledge, debug() is the way to go for that.
That said? Even with an army of expert frontend developers well-versed in automation infrastructure, we've had TONS of issues with even traditional mocha cypress implementation stability so, frankly, the issue very well may not be on you =|
*Thread Reply:* I just mean using my IDE and putting a red stop sign on a line of code. then clicking play,.
*Thread Reply:* it works in ruby (obviously), but it also works in raw selenium code. But for some reason using cypress or other stuff makes it not work. I've not got the knowledge to work out why.
*Thread Reply:* Also I'm not comfortable in changing cypress config yet (let alone on the fly), so I'm testing in electron which is super bad.
*Thread Reply:* I managed to get the cypress cucumber one working quite reliably now. The main issue I have now is that of debugging / traceability.
I.e. when I run it outputs an xml file with no stacktrace (or a complex one), I want a nice easy stacktrace to work out what line is failing, and also a way to get things like logging to file and browser config working. But I made ok progress.
In the upcoming TS release are the cli helpers such as getTestCasesFromFilesystem being removed? I can't seem to see them. Perhaps they have been renamed
*Thread Reply:* I'm guessing this is no longer available? I can see the code in cucumber.js but it doesn't appear to be accessible
*Thread Reply:* Still struggling with this (https://github.com/cucumber/cucumber-js/issues/1489) @Aslak Hellesøy
Given that cucumber-js does not have a --watch option, how are people running their tests automatically on file changes?
*Thread Reply:* Real talk:
I don't 🙈
We have a @wip tag for running scenarios/features under active development and I just hit that script. That said, it's mostly because we just haven't had time/prioritization to fiddle with a watcher. One of the FEs in my org would probably have a much cleverer solution 😁
*Thread Reply:* Honestly I never even thought of implementing a watcher, but what I would recommend using if you wanted to add a watcher is using gulp https://gulpjs.com/docs/en/api/watch This will work with typescript too
can someone please suggest how can I do the following? Let’s say I have a step where I create a variable= X. The I have next step where I want to use X as input value. Similar I want to pass data from one scenario to the other. We use Typescript as main language. Any help will be greatly appreciated
*Thread Reply:* Generally speaking, passing data from one scenario to another is considered an anti-pattern. Ideally, you want to keep them as separated as possible. Could you give an example of the sort of use-case you're trying to implement?
*Thread Reply:* @jradom https://stackoverflow.com/a/61241558/1267688 here is an example of how to pass data between steps. As for passing between scenarios, it's possible but not recommended because it violates test isolation between scenarios.
can someone help?How do i execute tree
it says no such command found .... debian secondly how do i open or run on windows?
*Thread Reply:* First of all: no need to post your question twice 🙂
You need to install it through apt install tree. You might need root permissions (prefix with sudo, sudo apt install tree.
I cannot answer your question related to Windows.
can someone help? How do I execute tree command
it says no such command found... Debian secondly, how do I open or run on windows? Thanks
fwiw here's my cucumber.js I do use babel.
module.exports = { default: `--format-options '{"snippetInterface": "synchronous"}' --require-module @babel/register --require-module @babel/polyfill --require-module ./node_modules/cypress --require ./cypress/support/step_definitions/`
};
I'm not sure how necessary some of these requires are, but that's the state of things now as I experiment.
@Thomas G Henry can you wrap yur code in three ` on each side here in slack? Makes it much easier to read 🙂
*Thread Reply:* It was a copy paste from the other channel. the backticks didn't make it 😊 updated now
// When(/^I login as {string}$/, (role: string) => {
// When('I login as {string}', function(role) {
When('I login as Faculty', function() {
// console.log(role);
// const username = getUserFromRole(role);
// const dashboardEndpointOverrides = getDashboardExpectationsFromRole(role, 'Root');
// console.log(username);
// console.log(dashboardEndpointOverrides);
// loginWithSSO(username, dashboardEndpointOverrides || ['/']);
return 'pending';
});
Not sure bout any of this but you should probbly only require cypress and not ./node_modules/cypress
*Thread Reply:* I had to fiddle with this a bit when I trying to run cucumber directly, but now I have picklejs in the mix and that seems to run cucumber from cypress, so I might not even need that at all anymore. I'll take it out now to see if that even matters.
mostly comments now, but left there to show things attempted. right now it blows up doing almost nothing
per the picklejs doc I have the step def dir under cypress. Maybe that features isn't in the root of the project is causing weirdness? They're being found, but maybe the unexpected location is having side effects. I'll play with the config, per the other thread and move the features around, and get back here. thanks, all!
Sorry, Friends. Had to take a call. So, here's the config:
module.exports = {
default: `--format-options '{"snippetInterface": "synchronous"}'`
};
Requiring babel and cypress no longer appear to matter at all. (they were leftover from calling cucumber directly, as opposed to via picklejs as I do now)
Also, I made a link to ./cypress/support/step_definitions from ./features/step_definitions
none of the above appear to have made a difference in this.cwd not being a string when resolving the step defs.
When isn't When When? When it's from "cypress-cucumber-preprocessor". Switching to that one from the vanilla cucumber one was what I needed. And it only cost me a day! haha
Hello! Is there a way to (more) gracefully interrupt a running test? Our tests tend to be long running, and our platform has some UI where we’d like to be able to stop a test
*Thread Reply:* More gracefully than...? You have a few options built in (for example: setting the timeout at config level), and there are a few things you could implement yourself.
*Thread Reply:* Usually it's helpful to identify long-running scenarios and either break them into shorter scenarios or identify the underlying cause of poor performance and remedy it
*Thread Reply:* Hi Cat, some more details: Our tests are a little unique, in that we’re testing videos, which can take some time before we make our assertions. So, we necessarily have some cucumber steps where we start something happening and we simple have to wait some time.
*Thread Reply:* One way I found to stop a test is in the world, I listen for a stop event. If one occurs, I throw a “Test stopped” error in the world itself.
*Thread Reply:* Hm. So basically
Given I go to MyPage
When I click MyVideo
And I wait for the video to play
Then I see <whatever the completed state is>
Right?
So when you say you're listening for the stop event - do you mean the video has unexpectedly stopped before it has completed? (trying to make sure I understand the scenario)
*Thread Reply:* If that's wrong, you can send me a (sanitized, if you need to) scenario so I grok it and I can help 🙂
*Thread Reply:* Hi Cat, your scenario is pretty close, so let’s go with that. So, let’s say that scenario is running, and currently we’re waiting for 10 minutes worth of video to play.
We have some UI that let’s us monitor running tests. In some cases, we might have to cancel the test manually. So, we have a button on the UI, and we can send a stop request to our server.
*Thread Reply:* So, we’d like to be able to stop the test from outside cucumber, but still allow it to execut after hooks
*Thread Reply:* Hm. To my knowledge, canceling the entire process manually would not allow you to execute the after hooks since it would end the entire process. However, you could ditch the after hooks and implement them as before hook cleanup and bypass the entire issue potentially
*Thread Reply:* alternatively, you could write an entirely separate script that runs independently that could be executed manually upon manually stopping the tests.
*Thread Reply:* okay, will look into that, thanks. sounds like there’s no way natively in the library to “interrupt” the steps. thanks for your time 🙂
*Thread Reply:* Short of setting a timeout or conditional stop, no, not that I can think of off the top of my head - that would not work with the manual stop use case though =|
*Thread Reply:* I've written automation with video and it can suck given the set time restraint based on video playback. 😞
*Thread Reply:* If possible, I'd recommend trying to use short videos wherever possible. Also, if you know the length of the video, you can put in a wait for the duration before moving on so that if things hang, you're not sitting indefinitely at least.
I know always using short sources isn't possible, especially since some issues only present themselves in long running sessions.
*Thread Reply:* Thanks, yeah that’s exactly the issue. We do use short videos when possibly. But we’re actually measuring latency drift in long running videos, so that’s where this scenario comes up. Sometimes we actually have to let the video run up to 3 hours!
*Thread Reply:* @ec-mark this might sound crazy… and I’m a complete amateur to your domain… but….
I wonder if an automated test like this is the best way to measure something like that.
Is it possible to think of a way to test latency drift in production?
I mean instrument the app in someway to provide you the data you need while users are actually playing videos? You could then have alerts if things start to go out of the boundaries you set for normality.
*Thread Reply:* ^^ That would actually be my suggestion as well, @tooky. It's how I would measure poor performance in, say, a long-running date aggregation. I don't see why the same principle couldn't be applied to videos.
@here i am starting new project with cucumberJS and trying to setup project structure. However, i see that we need to have step definitions and feature files in feature directory ..is there any way we can override this setting? like we specify glue path in cucumber-jvm which links feature to step definitions..is similar option available in cucumber js?
depending on the framework you’re going to use you can specify the cucumber options to tell where to find the steps definitions and the support files
*Thread Reply:* I am not using any other framework…using cucumber for writing automation tests and have own library built for invoking rest apis
*Thread Reply:* Ok, i figured this out…we can achieve this using profiles in CLI…Thanks you !!
@here, I have a question specific to cucumber scenario outline. Is there a way to generate dynamic values under scenario outline examples? I'm using javascript as the implementation language in my project.
For example, in below table I need to generate today's date dynamically instead of hardcoding the date.
Examples: | locationId | date | | 12345 | today |
Thanks in advance.
*Thread Reply:* Not directly in the .feature file, but you can accomplish that in the steps files, which are js files
*Thread Reply:* Thanks Marco.. can you share any references to follow?
*Thread Reply:* I don’t have a reference in itself, but that’s an idea that could help ☝️
*Thread Reply:* This helps.. I'll try this way.. Thanks Marco..
I may be missing a point somewhere, but I’m looking at the picklejs docs, and this seems to be entirely missing the point - there’s a load of grammar about interacting with elements etc, but this seems to be to be blurring behaviour and implementation; My scenarios should be specifying how the app behaves in ubiquitous language for the problem domain, not describing what I am clicking on.
I can use Cypress (or something else) to do the actual clicking and exploring, in steps… it seems like an abstraction too far to be using Gherkin to describe interaction with the DOM
```Background: Given I have created a new shop And I have entered the shop customizer
Scenario: Default Colors
When I check to see what I can customize Then I see that color is an option
When I select the color customizer Then I will see options to customize the primary, secondary, and background settings
When I check the default settings for primary colors Then I will see that the components are blue And the text color is white
When I select the primary color customizer And I set the components color to red And the text color to black Then the text on the language bar should be black And the bar should be red```
and then do the actual steps using cypress or puppeteer or something
No I think you’re exactly right - you should be able to rebuild your UI - different framework, different details/components - and just have to update some step code, not change any gherkin.
I’ve gone as far as to add lint rules to prevent words like “click” and “screen” being used in step text.
(If it works for some folks that’s all good...but yeah not really BDD)
Thanks! I guess my objection to this is two-fold; firstly on general BDD principles, but secondly because it gives Gherkin/Cucumber a bad name, because it really is just overhead - there’s no benefit to trying to write the actual mechanisms of element/ui interaction, or object instantiation in Gherkin - in fact it’s counter-productive - there are better tools with more powerful paradigms available, which you’re going to have to use anyway in your step definitions in most cases; so you did neither one thing (express the behaviour in the language of the domain, common to users and stakeholders) nor did you actually write code that does the actual testing - you just did a middle ground abstraction layer. If people think / see / believe that’s what Gherkin is for, I can well understand why people generate resistance. That’s why I always insist that Gherkin/Cucumber is about the “C”s - conversation, collabaoration, concerete examples, and counter-examples.
This might be a bit of an IDE-specific question, but we can try… I’m using IntelliJ IDEA (Ultimate) as my IDE, but writing Javascript tests… when the IDE offers to generate a step for me, it’s trying to do it using Java. Does anyone have any idea how to encourage it to do that in Javascript? No big deal to do it manually, but if there’s a way to do it, it’d be cool.
I think by default IntelliJ has plugins activated for cucumber JVM which help you with Java or Scala - you can also activate the (still first party) cucumber js plugin and then it’ll recognise steps in JavaScript or TypeScript
So I have a general question… I’m absolutely not a front-end dev - I’m not confident with DOM concepts, and have only ever been a backend person - I’ve mostly written APIs and CLIs — with that context: a friend of mine has written the beginning of a simple turn-based card game - the game begins with two hand of cards dealt and some on the table. I know the rules of the game, and thought it’d be fun to try to write tests for them. Of course because the game is already written, I’m having to test the implementation… but I wonder if one were writing this test first, what would one’s thinking be like? The behaviour I want is to see 6 cards face down (belonging to the computer), 6 cards face up (belonging to the human), and 4 cards face up (the starting point of the game). That’s easy to express in Gherkin, but the steps would force me to think about how to present these as elements / components, I guess? I find it very interesting to think about, but as a person without expertise in this domain, I’m genuinely curious to know how a person would do that.
*Thread Reply:* Nifty thing: I have a similar background - I started in backend and services and only started working in JS at all about 3.5 years ago 🙂 Would it be helpful to look at boilerplate projects like this one? Obviously this is highly abstracted for generic browser testing use (and this uses the webdriverio running with cucumber config’d, rather than cucumber runner wrapping wdio as its browser driver), but might help you see how it would be implemented: https://github.com/webdriverio/cucumber-boilerplate
Hi there. I have a question how to configure Cucumber to output test results as messages in an ndjson file. I have seen this repository https://github.com/cucumber/cucumber/tree/master/messages but got no answer
n the feature file: I used datatable like this: Background: Given James is at the portal page And he login to the portal |name|role| |james|global admin| , what is the syntax like in Typescript/JS in the step definitions? how do I pass in the parameter to call a function Login.of() to pass in the parameter from the table? here my step definitions: and(/(?:he|she|they) login to the portal/, () => actorInTheSpotlight().attemptsTo(Login.of(name,role)), ));
*Thread Reply:* Hi @LayMui I responded in the main #help channel, but I think this might help: https://cucumberbdd.slack.com/archives/C60TKS3SL/p1591394971489400
*Thread Reply:* I would then access the contents of the dataTable as dataTable.name and dataTable.role.
*Thread Reply:* I think my issue is the syntax for Typescript: here is my code snippet: and(/(?:he|she|they) login to the portal/, (table) { const input = table.hashes(); const name = input[0].name;const role = input[0].role; and I got this compilation error: [test:execute] Property 'answeredBy' is missing in type 'RegExp' but required in type 'Expectation<any, unknown>'.
*Thread Reply:* TypeScript is not my specialty. There may be others more familiar with TypeScript that can explain what’s gong on here. I’m not sure which line is throwing the RegExp/Expectation error you’re seeing.
I was trying a basic url launch in wdio cucumber,
ReferenceError: browser is not defined
is the displayed error
*Thread Reply:* You should probably check the webdriverio gitter channel - the CLI for wdio isn’t the same as that for cucumberjs
I'm testing an API with Cucumber, where the user supplies a URL as input, and then the back end server fetches it and does something with it (In particular it is an OpenID Connect Discovery Document). The issue I have is that in our feature files I'm not sure what URL to put in, since it is an environment setting and comes from that, so it depends on the machine. Right now I am doing something like "[WIREMOCK_URL]" in the feature file but then in every step definition involved I have to do a string subtitution, which is annoying.
Is there some built in way to have feature file reference externally defined variables, or some other solution to this problem.
Does CucumberJS by chance have a hook I can use to preprocess the feature files?
*Thread Reply:* yes, this should help you…https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/hooks.md
Error: Unexpected token 'export'
I'm unable to run because of the export error
Hi all, is there any way using the cucumber cli (or otherwise) to scan a directory containing step definition files and output them somewhere? I’m basically looking for a way to provide a list of step definitions that have been implemented in my platform programmatically
@ec-mark this will be possible when https://github.com/cucumber/cucumber-js/issues/1369 is fixed. Use --format message:cucumber.ndjson . You'll then find the step definitions in cucumber.ndjson . More info here:
https://github.com/cucumber/cucumber/tree/master/messages https://github.com/cucumber/cucumber/blob/master/messages/messages.md#io.cucumber.messages.StepDefinition
*Thread Reply:* That's great, thank you! I will track this and try it out when ready
Hi everyone. I would like to know if is there a way to log in on the console the steps in real-time, I mean the step description when it is running. I'm working with CucumberJS. Thanks!
so you want to debug in process?
I would advise either using a debug package (npm I think for you), or I cheat and use RubyMine (part of intellij family), I think your equivalent would be webstorm?
I just want to see where a Step start because in that way I can see the information that I'm showing is running inside that Step
because with that option, you can put something like console.log(step) and is a way to fix it
hang on i'm confused. You know when a step is running because you will be in the step def code?
So you could use an afterstep and then state the scenario step at each time?
I'm still not 100% sure what the issue was, but if you're sorted then well done for doing it.
I am relatively new to cucumber. I have set up my own project but I would like to create a page which I can import so it will be used to control opening the browser
right now, I would have to add this on everypage because if this is missing I will get an error saying findElement is undefined ``` driver = new webdriver.Builder() .withCapabilities(webdriver.Capabilities.chrome()).build();
}```
*Thread Reply:* Hi @Abdulaziz - have you considered asking the Selenium/WebDriver community about this? I don't see how this is related to Cucumber.
*Thread Reply:* One option could be store your driver instance in a variable , then have a method to get that instance - getWebdriverInstance() . As Aslak said not a cucumber question
hello!! i have a question, i want to use same step definition for 2 identical features files with differente tag, is possible to match step definitions files with feature through the tag that i created????
Hi, Anyone have any articles or know how to in cucumber.js get the test name into a step definition ? I tried export const getTestName = scenario.pickle.name and then calling this in my step devs via import but the export throws an error. So question is how can I pass test name into my step defs?
*Thread Reply:* Hello @Richard - I do this to populate a value before each step: ```const { Before } = require('cucumber');
Before(async function (scenario) { this.testname = scenario.pickle.name;
// if we need to grab a screenshot this.shortname = scenario.pickle.name .toLowerCase() .split(' ') .join('-');
});```
*Thread Reply:* Thanks @sonja leaf bit late 🤦♂️:skintone5:. Didn’t see this till now
Hi .. is there any good course or document for cucumber + webdriver + react .. I am trying to test a button click event
*Thread Reply:* https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/hooks.md
Hi Everyone Has anyone got an example cypress - cucumber style project structure?
*Thread Reply:* you can check this out… https://github.com/davidjgoss/cucumber-puppeteer-typescript-starter
*Thread Reply:* be aware of the cucumber cypress option about global step definitions being turned off by default
hi all in javascript, how to pass object and array of objects over step ?
*Thread Reply:* Please give us more details of what you are trying to achieve.
*Thread Reply:* I have function that take array of objects and reformat its content
*Thread Reply:* @seb I solved it
for object, use rowsHash function to get object structure from data table in step
for array, use hashes function to get array of objects from data table in step
I am following the tutorial for cucumber-js but when I do npm i -D cucumber in my fresh directory no node_modules dir is created. I have tried other packages, and they work fine, but not the cucumber ones. Any ideas?
*Thread Reply:* ```$ mkdir shouty [utahcon@beast utahcon]$ cd shouty/ [utahcon@beast shouty]$ ls -al total 8 drwxrwxr-x. 2 utahcon utahcon 4096 Aug 20 13:08 . drwxrwxr-x. 27 utahcon utahcon 4096 Aug 20 13:08 .. [utahcon@beast shouty]$ npm init -y Wrote to /home/utahcon/Projects/src/github.com/utahcon/shouty/package.json:
{ "name": "shouty", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC" }
$ npm install -D cucumber npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN shouty@1.0.0 No description npm WARN shouty@1.0.0 No repository field.
audited 77 packages in 2.507s found 0 vulnerabilities
$ npm --versbose install -D cucumber npm WARN shouty@1.0.0 No description npm WARN shouty@1.0.0 No repository field.
audited 77 packages in 2.196s found 0 vulnerabilities
$ npm --verbose install -D cucumber npm info it worked if it ends with ok npm verb cli [ npm verb cli '/usr/bin/node', npm verb cli '/usr/local/bin/npm', npm verb cli '--verbose', npm verb cli 'install', npm verb cli '-D', npm verb cli 'cucumber' npm verb cli ] npm info using npm@6.14.8 npm info using node@v12.18.3 npm verb npm-session 1cae8be88e4a4053 npm http fetch GET 304 https://registry.npmjs.org/cucumber 190ms (from cache) npm timing stage:loadCurrentTree Completed in 260ms npm timing stage:loadIdealTree:cloneCurrentTree Completed in 0ms npm timing stage:loadIdealTree:loadShrinkwrap Completed in 97ms npm http fetch GET 304 https://registry.npmjs.org/assertion-error-formatter 76ms (from cache) npm http fetch GET 200 https://registry.npm ... npm timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 1701ms npm timing stage:loadIdealTree Completed in 1835ms npm timing stage:generateActionsToTake Completed in 15ms npm verb correctMkdir /home/utahcon/.npm/locks correctMkdir not in flight; initializing npm verb lock using /home/utahcon/.npm/locks/staging-5cbe75a208033ad6.lock for /home/utahcon/Projects/src/github.com/utahcon/shouty/nodemodules/.staging npm verb unlock done using /home/utahcon/.npm/locks/staging-5cbe75a208033ad6.lock for /home/utahcon/Projects/src/github.com/utahcon/shouty/node_modules/.staging npm timing stage:executeActions Completed in 15ms npm timing stage:rollbackFailedOptional Completed in 1ms npm timing stage:runTopLevelLifecycles Completed in 2179ms npm verb saving [ { name: 'cucumber', spec: '^6.0.5', save: 'devDependencies' } ] npm verb shrinkwrap skipping write for package.json because there were no changes. npm info lifecycle undefined~preshrinkwrap: undefined npm info lifecycle shouty@1.0.0~shrinkwrap: shouty@1.0.0 npm verb shrinkwrap skipping write for package-lock.json because there were no changes. npm info lifecycle shouty@1.0.0~postshrinkwrap: shouty@1.0.0 npm WARN shouty@1.0.0 No description npm WARN shouty@1.0.0 No repository field.
npm timing audit submit Completed in 228ms npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/audits/quick 229ms npm timing audit body Completed in 1ms audited 77 packages in 2.398s found 0 vulnerabilities
npm verb exit [ 0, true ] npm timing npm Completed in 2999ms npm info ok
$ ls -al total 36 drwxrwxr-x. 2 utahcon utahcon 4096 Aug 20 13:09 . drwxrwxr-x. 27 utahcon utahcon 4096 Aug 20 13:08 .. -rw-rw-r--. 1 utahcon utahcon 273 Aug 20 13:09 package.json -rw-rw-r--. 1 utahcon utahcon 23232 Aug 20 13:09 package-lock.json```
*Thread Reply:* I have no idea @Utahcon - it sounds like it's related to your node and/or npm installation. I've followed the same steps as you and ls -al node_modules | wc -l reports 79 for me.
Hello, I am trying to call cucumber programatically from inside a node.js function.
I have gotten as far as
const reqd = require('cucumber');
const cliArgs = {
path: "./features/mySecond.feature"
};
let cli = new reqd.Cli(cliArgs);
await cli.run();
But I cannot figure out how to properly format the arguments to pass into cli.run. If anyone can share an example, point me to documentation, or a github issues thread that would be awesome. the cliArgs object that I have is not correct.
I have read https://github.com/cucumber/cucumber-js/issues/786 and looked at the source code here: https://github.com/cucumber/cucumber-js/blob/master/src/cli/index.ts and here: https://github.com/cucumber/cucumber-js/blob/master/src/cli/run.ts
Ok, I figured out a set of arguments that works to at least get it running:
const cucumber = require('cucumber');
const stream = require('stream');
const outputStream = new stream.Writable();
outputStream._write = async function (chunk, encoding, done) {
context.log(chunk.toString());
done();
};
const runArgs = ['node', 'cucumber_js'];
const cli = new cucumber.Cli({argv: runArgs, cwd: process.cwd(), stdout: outputStream});
cli.run();
*Thread Reply:* There isn’t - attachments have no naming, it’s just their content and their media type
I am trying to figure out how to pass feature files to cucumber as strings.
I have the same use case as @chamberlainpi , who asked here: https://github.com/cucumber/cucumber-js/issues/1308
> [Is there] any way to use [cucumber js] as a node module, like importing/requiring the cucumber library and running tests by passing the features as an array of strings, instead of pointing to a folder of features files. > Something along the lines like: ```const cucumber = require('cucumber'); const featuresArr = loadFeaturesStrings('http://some.where.com/');
const results = await cucumber.run({ features: featuresArr, steps: require('./steps.js') });``` That is exactly what I want to do. I want to give my users a GUI that will let them create features. Then I want to take the features that they have created and pass them to cucumber as a parameter of an async function. I want to await the execution of cucumber, get the results back, then display the results to my users.
But I have been working on this for days and I cannot figure out what I need to do to make it work.
@Izhaki responded to chamberlainpi's post. Izhaki says
> This is possible, and exactly what is done in the browser example, specifically here:
const gherkinMessageStream = Gherkin.fromSources(
[
messages.Envelope.fromObject({
source: {
data: featureEditor.getValue(), // < getValue() returns a feature as string
uri: 'example.feature',
},
}),
],
{ newId }
)
I looked at the code in the example that Izhaki linked and I can't figure out how to reproduce it locally.
I see that index.html uses two scripts, cucumber.js and browser-example.js.
<script type="text/javascript" src="cucumber.js"></script>
<script type="text/javascript" src="browser-example.js"></script>
I'm having real difficulty making a working file based on the browser example index.ts because it seems like the example code is using a different export than I am getting from the cucumber I have installed in node_modules.
The example code generates gherkinMessageStream, then uses Cucumber.parseGherkinMessageStream to parse it into an array of strings assigned to const pickleIds.
const pickleIds = Cucumber.parseGherkinMessageStream({
But I get
TypeError: Cucumber.parseGherkinMessageStream is not a function
Also, there is no parseGherkinMessageStream exported from the node_module cucumber. I searched the folder and couldn't find anything called parseGherkinMessageStream.
I can see the code for parseGherkinMessageStream in src/cli/helpers.ts on github. But I have not been able to access it using cucumber from my node_modules folder.
If I comment out the use of parseGherkinMessageStream and just assign an empty array to pickleIds,
const pickleIds: string[] = [];
cucumber does run and outputs
0 scenarios
0 steps
0m00.000s
So I feel like I am close. But I am completely stumped at this point. I have read the docs and everything I could find on the internet & stackoverflow.
Here's my whole index.ts file. How can I get this working?
```import { EventEmitter } from 'events'; import Gherkin from 'gherkin'; import { messages, IdGenerator } from 'cucumber-messages'; const Cucumber = require('cucumber');
const featureString = `Feature: Simple maths In order to do maths As a developer I want to increment variables
Scenario: easy maths Given a variable set to 1 When I increment the variable by 1 Then the variable should contain 2
Scenario Outline: much more complex stuff Given a variable set to <var> When I increment the variable by <increment> Then the variable should contain <result>
Examples: | var | increment | result | | 100 | 5 | 105 | | 99 | 1234 | 1333 | | 12 | 5 | 18 |`;
const { uuid } = IdGenerator;
async function runFeature(): Promise<boolean> { const eventBroadcaster = new EventEmitter();
const eventDataCollector = new Cucumber.formatterHelpers.EventDataCollector(
eventBroadcaster
);
const newId = uuid();
const gherkinMessageStream = await Gherkin.fromSources(
[
messages.Envelope.fromObject({
source: {
data: featureString,
uri: 'example.feature',
},
}),
],
{ newId }
);
const pickleIds = Cucumber.parseGherkinMessageStream({
cwd: '',
eventBroadcaster,
eventDataCollector,
gherkinMessageStream,
pickleFilter: new Cucumber.PickleFilter({ cwd: '' }),
order: 'defined',
});
Cucumber.supportCodeLibraryBuilder.reset('', newId);
const supportCodeLibrary = await Cucumber.supportCodeLibraryBuilder.finalize();
const formatterOptions = {
cwd: '/',
eventBroadcaster,
eventDataCollector,
parsedArgvOptions: {
colorsEnabled: true,
},
log(data: string) {
console.log(data);
},
supportCodeLibrary,
};
Cucumber.FormatterBuilder.build('progress', formatterOptions);
const runtime = new Cucumber.Runtime({
eventBroadcaster,
eventDataCollector,
newId,
options: {},
pickleIds,
supportCodeLibrary,
});
return runtime.start();
}
runFeature();```
*Thread Reply:* Hi, I haven’t studied your example in detail, but we have recently added a programmatic usage of the cli to the project here https://github.com/cucumber/cucumber-js/blob/master/compatibility/cck_spec.ts - lots of that code is related to the testing/assertions it’s doing but hopefully it helps
Hi folks, is it possible to access the world (a custom world in my case) from an After(...) hook?
*Thread Reply:* Also, not directly related, but is normal for a world to be constructed multiple times for one scenario?
Using cucumberjs 6.0.5 by the way
*Thread Reply:* Yes you can access the World from an After hook (but not AfterAll). It’ll be the value of ‘this’ (make sure you don’t use an arrow function)
*Thread Reply:* You should expect one stance of World to be created for every scenario that runs (for a scenario outline, that’s one per example)
*Thread Reply:* yes, I found that, thanks 🙂
I did not dig into it, but I put a logging line in my custom world's constructor, and I saw 3 instances of it created
my feature only specifies 1 scenario (no outline being used)
*Thread Reply:* didn't harm anything for me, so I moved on. After(...) is only executed once
*Thread Reply:* Okay, are you able to put an example up somewhere we can reproduce that?
Also just a thought, are you using the retry feature?
*Thread Reply:* not using the retry feature. I can probably get an example up sometime next week 🙂 too late in the day on a Friday
Hello. So I learned a bit of cucumber a while ago but I'm a bit rusty. Today I wanted to implement a series of very similar scenarios with a change in string. So after some digging I found how to set up a scenario outline and table (sadly, the correct syntax appears not to be available in the main documentation). Anyway, now I have only added one case and got my scenario to run to completion (all the steps to pass are running). However, the scenario fails with the following error. Simply googling this error doesn't appear to give any useful results. Any tips?
[0-0] 2020-09-01T20:56:06.597Z ERROR @wdio/runner: TypeError: Cannot read property 'indexOf' of undefined
at /...../git/test-project/node_modules/@wdio/cucumber-framework/build/utils.js:85:20
at Array.forEach (<anonymous>)
at /...../git/test-project/node_modules/@wdio/cucumber-framework/build/utils.js:84:35
at Array.forEach (<anonymous>)
at getUniqueIdentifier (/...../git/test-project/node_modules/@wdio/cucumber-framework/build/utils.js:83:23)
at CucumberReporter.handleAfterScenario (/...../git/test-project/node_modules/@wdio/cucumber-framework/build/reporter.js:175:43)
at CucumberEventListener.emit (events.js:310:20)
at CucumberEventListener.EventEmitter.emit (domain.js:482:12)
at CucumberEventListener.onTestCaseFinished (/...../git/test-project/node_modules/@wdio/cucumber-framework/build/cucumberEventListener.js:135:10)
at EventEmitter.emit (events.js:310:20)
at EventEmitter.emit (domain.js:482:12)
at TestCaseRunner.emit (/...../git/test-project/node_modules/cucumber/lib/runtime/test_case_runner.js:92:27)
at TestCaseRunner.run (/...../git/test-project/node_modules/cucumber/lib/runtime/test_case_runner.js:227:12)
at async Runtime.runTestCase (/...../git/test-project/node_modules/cucumber/lib/runtime/index.js:76:28)
[0-0] Error: Cannot read property 'indexOf' of undefined
[0-0] 2020-09-01T20:56:06.598Z INFO webdriver: COMMAND deleteSession()
2020-09-01T20:56:06.598Z INFO webdriver: [DELETE] <http://localhost:4444/wd/hub/session/42febe7e-5152-8849-839c-5d37dc4ac9fb>
[0-0] FAILED in firefox - /src/featureFiles/CustomerWebPortal/Booking/square.featur
*Thread Reply:* Looks like it is a js equivalent of "array index out of bounds"? https://stackoverflow.com/questions/24911859/cannot-read-property-indexof-of-undefined
*Thread Reply:* This is my scenario outline: ```Scenario Outline: When I make a booking with <card> card Then the booking is created
Examples: | card | | Visa | ```
*Thread Reply:* I made a PR to the wdio repo that fixes this but I am surprised it doesn't appear anyone else has run into it.
Hello, I've been having a lot of trouble with random build failures. Running cucumber and protractor on a local angular app in cicd.
Same code base, it will pass a hand full of times, then randomly, 76/85 tests will fail and many of the failed tests (Not all of them) will have this in the logs:
NoSuchSessionError: invalid session id
Its like one of the tests fails, and that seems to brick selenium or something
*Thread Reply:* For anyone mildy interested, I think what happened is on a resource poor system, when a couple of the tests failed because of a timeout, either selenium or protractor crashed, which fails the rest of the tests.
*Thread Reply:* I know you posted this a long time ago, but the times I have seen that, it usually indicates some sort of race condition. Let's say, you forgot an await on something, and 95% of the time it executes just in time, but on those 5% of times it doesn't and browser session is killed, it will throw that.
*Thread Reply:* Thanks @Kārlis Amoliņš I upgraded typescript and tslint to the latest and made use of the new newer lint rules to find the missing awaits, looks like its stable now. Cheers
Hi! Did someone know a workaround to allow BeforeAll hook have access to World instance? I have a case where I want to attach some info to the test report about testing environment and I want to use this.attach() method.
Hi, BeforeAll hooks don’t have access to a world because a world belongs to a scenario, and BeforeAll happens before any scenarios. There is some discussion on this issue https://github.com/cucumber/cucumber-js/issues/1393 including a possible way forward
*Thread Reply:* Yes, I know. I read this discussion. Hovewere I was thinking how to make this possible. I was trying with call() method to share contex from customWorld but without luck.
Interesting @David Goss I raised this as an issue a couple of months ago in cucumber-ruby. Good explanation, kinda think we should rethink it generally.
One idea, but no idea how. Is to make the BeforeAll world sort of "more stateful", and have the variables set there auto-created for each run. A bit like it would happen in rspec for example.
Hi All, I'm trying to implement protractor-cucumber-framework from scratch. I got my file working as well. now as a next step I'm trying to implement POM for the same script, but first i need to make my script work without asynchronous call back.I tried to implement synchronously but its throwing error . I do not wish to implement POM with asynchronous callback .Can someone please point me to right direction, or tell me where I'm going wrong with my current code. The application I'm testing is angular only so the error message is not helpful.
*The first step file that is working fine with callback, it stops working if i remove the callback, Error is shown below*
*Feature file* *example data is dummy*
```Feature: Automation Testing for the login module of Asterisk sc solution
Scenario Outline: Scenario Outline name: Login and Verify user
Given User is redirected to <site>
When User inputs <username> and <password>
Then User should be successfully logged in with their <name>
Examples:
| site | username | password | name |
| <http://dummydata/> | xyz | password12 | dummy |```
*StepDefinition file*:
```const { Given, When, Then } = require("cucumber"); var chai = require('chai'); var chaiAsPromised = require('chai-as-promised'); const { browser, element } = require("protractor"); chai.use(chaiAsPromised); var expect = chai.expect; var { setDefaultTimeout } = require('cucumber');
setDefaultTimeout(60 ** 1000);
/these are page element locators- needs to be shifted to PO file and reference needs to created here/
var username = element(by.xpath('/html/body/app-root/app-auth-main/div/div[2]/app-login/div/div/form/div[1]/input')); var password = element(by.xpath('/html/body/app-root/app-auth-main/div/div[2]/app-login/div/div/form/div[2]/input')); var loginButton = element(by.xpath('/html/body/app-root/app-auth-main/div/div[2]/app-login/div/div/form/div[3]/button[2]')); var userVerify = element(by.xpath('/html/body/app-root/app-main/app-header/div/div[2]/div/table/tbody/tr/td[2]/div[1]')); var logoutButton = element(by.xpath('/html/body/app-root/app-main/app-header/div/div[2]/div/table/tbody/tr/td[3]/ul/li/div/a[3]')); var loginHeader = element(by.xpath('/html/body/app-root/app-auth-main/div/div[2]/app-login/div/div/form/p')); var logoutdropdown = element(by.xpath('/html/body/app-root/app-main/app-header/div/div[2]/div/table/tbody/tr/td[3]/ul/li')); var teamName = element(by.xpath('/html/body/app-root/app-auth-main/div/div[1]/div/div/div/table/tbody/tr/td[2]/div/div[2]')) var loginError = element(by.xpath('/html/body/div/div/div[1]/h2'))
function login(a, b) { username.sendKeys(a); password.sendKeys(b); loginButton.click();
}
Given(/^User is redirected to (.*)$/, { timeout: 60 * 1000 }, function (site, callback) { browser.get(site); expect(loginHeader.isPresent()).and.notify(callback);
});
When(/^User inputs (.) and (.)$/, { timeout: 60 ** 1000 }, function (username, password, callback) { login(username, password); browser.sleep(2000); browser.getCurrentUrl().then(function (Url) { console.log(Url + " page reached, login successful.") }); expect(userVerify.isPresent()).and.notify(callback); });
Then(/^User should be successfully logged in with their (.*)$/, { timeout: 60 * 1000 }, function (name, callback) {
expect(userVerify.getText()).to.eventually.equal(name); logoutdropdown.click(); logoutButton.click(); browser.sleep(2000); browser.getCurrentUrl().then(function (Url) { console.log("login page " + Url + " reached. Test finished") }); expect(teamName.getText()).to.eventually.equal("Asterisk").and.notify(callback);
});```
*Conf.js* :
```// conf.js
exports.config = {
directConnect: true,
getPageTimeout: 50000,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities:{'browserName': 'chrome'},
specs: ['tests/feature/**.feature'],
cucumberOpts:{ require:'tests/stepdefinition/stepdefinition.js', tags: false, profile: false, 'no-source':true}, onPrepare: function(){ const {Given, Then, When} = require('cucumber'); global.Given = Given; global.When = When; global.Then = Then; browser.manage().window().maximize(); }
}```
*Step file that is failing* ```var chai = require('chai'); var chaiAsPromised = require('chai-as-promised'); const { browser, element } = require("protractor"); chai.use(chaiAsPromised); var expect = chai.expect; var { setDefaultTimeout } = require('cucumber'); setDefaultTimeout(60 ** 1000);
/these are page element locators- needs to be shifted to another file and reference needs to created here/
var username = element(by.xpath('/html/body/app-root/app-auth-main/div/div[2]/app-login/div/div/form/div[1]/input')); var password = element(by.xpath('/html/body/app-root/app-auth-main/div/div[2]/app-login/div/div/form/div[2]/input')); var loginButton = element(by.xpath('/html/body/app-root/app-auth-main/div/div[2]/app-login/div/div/form/div[3]/button[2]')); var userVerify = element(by.xpath('/html/body/app-root/app-main/app-header/div/div[2]/div/table/tbody/tr/td[2]/div[1]')); var logoutButton = element(by.xpath('/html/body/app-root/app-main/app-header/div/div[2]/div/table/tbody/tr/td[3]/ul/li/div/a[3]')); var loginHeader = element(by.xpath('/html/body/app-root/app-auth-main/div/div[2]/app-login/div/div/form/p')); var logoutdropdown = element(by.xpath('/html/body/app-root/app-main/app-header/div/div[2]/div/table/tbody/tr/td[3]/ul/li')); var teamName = element(by.xpath('/html/body/app-root/app-auth-main/div/div[1]/div/div/div/table/tbody/tr/td[2]/div/div[2]')) var loginError = element(by.xpath('/html/body/div/div/div[1]/h2'))
function login(a, b) { username.sendKeys(a); password.sendKeys(b); loginButton.click();
}
Given(/^User is redirected to (.*)$/, { timeout: 60 * 1000 }, function (site) { browser.get(site); expect(loginHeader.isPresent()); });
When(/^User inputs (.) and (.)$/, { timeout: 60 ** 1000 }, function (username, password, callback) { login(username, password); browser.sleep(2000); browser.getCurrentUrl().then(function (Url) { console.log(Url + " page reached, login successful.") }); expect(userVerify.isPresent()).and.notify(callback); });
Then(/^User should be successfully logged in with their (.*)$/, { timeout: 60 * 1000 }, function (name, callback) {
expect(userVerify.getText()).to.eventually.equal(name); logoutdropdown.click(); logoutButton.click(); browser.sleep(2000); browser.getCurrentUrl().then(function (Url) { console.log("login page " + Url + " reached. Test finished") }); expect(teamName.getText()).to.eventually.equal("Asterisk").and.notify(callback);
});
****error message****
PS C:\Users\dummyUser\Desktop\asteriskTestAutomation> protractor C:\Users\dummyUser\Desktop\asteriskTestAutomation\conf.js
[11:13:53] I/launcher - Running 1 instances of WebDriver
[11:13:53] I/direct - Using ChromeDriver directly...
DevTools listening on
Is there anyone here using cucumber-js running inside the browser? I'm not talking about running cucumber-js on Node and starting a browser with selenium, I'm talking about actually running cucumber-js inside the browser.
Currently we are using "@wdio/cucumber-framework": "^6.1.18", and we are launching all our tests via wdio command. I had tried to use cucumber command but it launched 0 tests. I am interested in the reports feature. Does @cucumber/cucumber play nice with @wdio? In the past on a different project we had used cucumber, and webdriverio dependencies instead.
*Thread Reply:* There is a short migration guide here: https://github.com/cucumber/cucumber-js/blob/master/CHANGELOG.md#700-rc0-2020-09-14
*Thread Reply:* Does @cucumber/cucumber play nice with @wdio ? Yes. Cucumber plays nice with anything you put inside your step definitions or hooks, because it is blissfully ignorant of what your code does. It just reports errors if your code throws errors.
*Thread Reply:* Ok I guess I'll have to see since I'm not exactly sure why when I was trying to run cucumber for my current test framework (which has a different dependency structure than a past one where I used webdriverio and launched things with cucumber, it was reporting 0 tests, vs running wdio commands. Perhaps I was using it incorrectly.
*Thread Reply:* I'll have to investigate. Thanks for sharing the migration guide!
Hello, my team ran into an issues with cucumber. We have identical step definitions for multiple test cases. For example: "User accepts terms and conditions", etc. We get an error "Multiple step definitions match". How can we use Cucumber without rewriting all of our test cases? Thank you.
*Thread Reply:* There are a few options. You can set it at configuration - when you pass the step defs in, just pass in the ones you want to use. You can also modify the step definitions themselves to have a conditional function that determines which behavior should be leveraged. However, the best practice is for your language to be expressive. Having ambiguous language that could indicate multiple different behaviors tends to bite you in the ass later.
*Thread Reply:* You should only need to write the step definition once. You can then re-use it in multiple tests. If you are attempting to write step definitions that have the same name but perform different actions, consider changing one of them to be more specific.
*Thread Reply:* @Cat - test manager wrote a large number of test cases/scenarios and she expects that it will be a big overload to rewrite them in a unique way. Since Cucumber is well known and widely used, I had a hope that there is a better and less time consuming solution.
*Thread Reply:* @Mona Ghassemi - I am not sure I follow your line of thoughts completely. We use Jenkins and Xray for Jira. We will have to have multiple feature files in one repository branch to be able to do testing and get report back to Xray. Let's say we have 100 test scenarios and 50% have steps which have to be repeated. The idea of rewriting the test scenarios is pushing our manager to get rid of Cucumber. Question - how to save Cucumber? 😄
*Thread Reply:* You don’t need a rewrite. You need abstraction.
*Thread Reply:* They don’t all need to be unique. Quite the opposite. They can be paramaterized in such a way that they can be quite flexible. It’s a time investment, but all test automation is (and should be). If she isn’t anticipating that, she got into the wrong line of business
*Thread Reply:* If it would be up to me - I would modify the test scenarios a bit. I even did add one extra word in the second scenario ("the user" instead of "user") to show my manager that we do not have to rewrite a lot. But she did not like it. She think that it will take a lot of maintenance to continue the project. 🧐 I disagree but ...
*Thread Reply:* @Cat - thanks for the input. I thought it was my duty to check if we can do something else on the test engineers side.
*Thread Reply:* @aberdan I don't think adding extra words like "the" is of any help. Cat's comments on abstraction and parametrization are on point.
*Thread Reply:* Part of the reason that you don’t want to have step defs that are too similar or identical is because it then becomes very difficult to determine what they’re doing. Look instead at the step definitions to see why they’re different. Are they actually that different? You may find that they aren’t, or you may find that some added conditional handling and state control will go a long way.
*Thread Reply:* The purpose of the scenarios is to express the behavior. If you have 5 different step definitions that do different things, but are verbally expressed the same way, that makes it harder to detangle the behavior, not easier, which defeats the point.
*Thread Reply:* If I say Given the user has logged in and one of my step defs logs into a completely different application, I’m screwing myself over. Even if it’s just a differently permissioned user or there are slightly different UI flows involved, it doesn’t necessarily express the state and, as a result, introduces confusion rather than eliminating it
*Thread Reply:* So given the situation, I’d consider timeboxing it to see how many step defs you have for a given thing and what they actually do. Are they doing the same thing, effectively? Do they maybe just have slightly different selectors? Can they be condensed to a single step def? That’s going to help you champion cucumber better if you can show the streamlined step definitions and expressive feature files
*Thread Reply:* As an example (terms and conditions page has two check boxes - for privacy policy and for terms and conditions): Scenario 1: Test accept privacy policy only Given user has activated account Then user navigates to terms and conditions page where terms and conditions can be reviewed And user can click the terms and conditions side bar to scroll down to the bottom of the page where check boxes are visible When user accepts only the privacy policy And clicks the Register button Then user cannot progress to the next page When user accept terms and conditions and privacy policy And then clicks the Register button again Then user is taken to the Utility Page
Scenario 2: Test accept terms and conditions only Given user has activated account Then user navigates to terms and conditions page where terms and conditions can be reviewed And user can click the terms and conditions side bar to scroll down to the bottom of the page where check boxes are visible When user accepts only the terms and conditions And clicks the Register button Then user cannot progress to the next page When user accept terms and conditions and privacy policy And then clicks the Register button again Then user is taken to the Utility Page
As you can see, only step #4 is different, all other steps are the same. And it is just one example, we have much more in our backlog in Jira. I do not write the Cucumber scenarios, I write JavaScript code for automated testing and we have no problems with JS. What should we do? Does the test manager have to write one Scenario for steps 1-3 and another scenario for steps 5-9? Which then can be reused when needed?
*Thread Reply:* ok so, firstly: you’re testing something twice. Imo, you need to have a distinct scenario for the positive case (acceptance of both policies). Then there’s a separate scenario for each of the negative conditions (having only one of the policies checked). Secondly: there are a few ways you can streamline this to be more elegant and have more DRY code. For example: All you have to say is “When user accepts <policy>” That’s a single step def that takes an arg. That’s all it has to be. Just have it take a parameter and, based on what you pass in, it clicks whichever checkbox. Similarly: “And then clicks the Register button again” - this is unnecessarily redundant. Just say “And clicks the Register button” - it’s the same action, no matter what. If it’s the same action, use the same words.
*Thread Reply:* These kinds of things will help make the code and the features less repetitive. It’ll become faster over time.
*Thread Reply:* It also helps you spot areas where the code can be abstracted to make it more efficient
*Thread Reply:* @Cat - a personal huge Thank you! Everything you said makes a lot of sense to me. I will try to convince my manager to restructure the test cases in a less redundant way. I hope she will listen. 🙂
hello I can't figure out why this AssertionError message gets lost
*Thread Reply:* I figured it out - these lines in node-assertion-error-formatter cause me to lose my assertion message because my message starts with "expected"
*Thread Reply:* node v12.16.1
shell
ReferenceError: shell is not defined
at repl:1:1
at Script.runInContext (vm.js:130:18)
at REPLServer.defaultEval (repl.js:435:29)
at bound (domain.js:427:14)
at REPLServer.runBound [as eval] (domain.js:440:12)
at <a href="http://REPLServer.onLine">REPLServer.onLine</a> (repl.js:760:10)
at REPLServer.emit (events.js:315:20)
at REPLServer.EventEmitter.emit (domain.js:483:12)
at REPLServer.Interface._onLine (readline.js:329:10)
npm run test-cucumber
npm should be run outside of the node repl, in your normal shell.
(Press Control-D to exit.)
npm run test-cucumber
npm should be run outside of the node repl, in your normal shell.
(Press Control-D to exit.)
*Thread Reply:* thanks for replying Mona. If you wait for the editor to load then press F1 while in one of the files, then type shell you should see this
*Thread Reply:* but I figured out the reason it was happening and posted it here ... https://github.com/charlierudolph/node-assertion-error-formatter/issues/3
Salutations Earthling! "Guys" is easily replaced with the more gender-neutral "Folks" or "All". We'd appreciate if you tried to use that. Thanks!
*Thread Reply:* we get TypeError: Cannot read property 'address' of undefined
*Thread Reply:* You should be able to use babel. (I assume you can also use webpack, but I’m personally more familiar w/babel).
*Thread Reply:* if we change it to module.exports = app cucumber works, but then our app doesn't build
*Thread Reply:* Right. Natively, cucumber isn’t going to be able to leverage commonjs exports. You have to configure that explicitly. It’s distinct from your application transpile.
*Thread Reply:* This discussion gives some high level instructions.
As mentioned, you’ll want to configure something to the effect of "presets": [["env",{"modules":"commonjs"}]]
You may need to fiddle around with it a bit. This was ~2 years ago, looks like, so some of the verbiage could have changed since then. When in doubt, check the babel docs.
*Thread Reply:* Ok. Without knowing how you’ve configured it, how you’re running it, what commands you’re using it, or anything about what you’re trying to run, there’s very little I can do to help other than point you in the right direction. 🤷
Hello All! I am new to the channel and pretty new to cucumber. I have an angular app that I am trying to implement the same way as the example in the repo, but am running into alot of trouble. Is there any articles, posts, or help that could steer me in the right direction. Basically i'm looking to have an exact replica of the example just in angular.
*Thread Reply:* That’s going to be an angular question - not a cucumber question.
Hello all
I have 2 feature files
Feature file 1
Scenario: Scenario 1
Given
When
Then
Feature file 2
Scenario: Scenario 2
Given
When
Then
here I have the same Given, When, and Then in the both files
so i get the following error
Multiple step definitions match
is this normal to have unique Given, When, and Then over the whole code ?
Given / When / Then are essentially just irrelevant (When writing steps)>
That's not to say they "should" be. Just they are at the moment.
Ideally though you would change the language for a given / when / then.
Given should be a Precondition - i.e. something has happened (Usually past tense) When should be an Action - i.e. something is happening (Present tense) Then is an assertion - i.e. you expect something (Future tense)
☝️ A guide. Not the set rules ☝️
Given I am called Harry When I select the user called Harry Then a user called Harry is present
your step definitions need to be unique. You can reuse the steps themselves within a feature file, but a specific step needs to be unique.
Hello, I'm trying to make a custom formatter to append timestamps to the json output, but am running into difficulties. I created a custom formatter that listens to the eventBroadcaster events, and am calling log(data), but the data isn't showing up in the json output. Was hoping for guidance on the proper way to get the custom formatter to show up in the json output
@Kyle Bailey the JSON formatter is deprecated: • https://github.com/cucumber/cucumber-js/blob/master/CHANGELOG.md#breaking-changes • https://github.com/cucumber/cucumber/blob/master/messages/README.md
Hi! Regarding custom parameters and regular expressions, if mine contains a union, must I wrap it in a capturing / non-capturing group to not let the union operator mess with the resulting expression or will Cucumber do that for me?
*Thread Reply:* Yes! Provided I have configured a parameter as shown below.
defineParameterType({
name: "foobar",
regexp: /foo|bar/
});
Furthermore I have a step definition like
When("I put a {foobar} in my inventory", (fooOrBar) => { ... });
My understanding is that cucumber-expression will compile an expression, but if the resulting expression is a mere interpolation EG. /^I put a foo|bar in my inventory$/ , then that will probably have unexpected results
*Thread Reply:* The expression will match these steps:
I put a foo in my inventory
I put a bar in my inventory
Anything else will not match. What do you mean by interpolation? What kind of unexpected results are you anticipating?
*Thread Reply:* I'm mostly curious at this point about the workings of cucumber-expressions and I'm not experiencing anything out of the ordinary or what you describe
*Thread Reply:* Am I correct to assume that using anchors for start / end of string will mess with it?
*Thread Reply:* Yes. Regular Expressions is a language with its own syntax rules. Cucumber Expression is also a language with its own syntax rules. You can't mix them. It's like Russian and Spanish.
@Aslak Hellesøy Just because it's deprecated shouldn't mean I'm unable to attempt what I'm doing. How about this. How can I write a custom formatter to write to a file from intercepting events, while simultaneously using the progress output via stdout?
*Thread Reply:* Of course - I just wanted to give you a heads up since we plan to remove the JSON formatter from future versions of Cucumber.
Have you seen this? https://github.com/cucumber/cucumber-js/blob/master/docs/custom_formatters.md
^^ @Kyle Bailey
*Thread Reply:* Ah, gotcha!
I have, and I made a custom formatter that does what I want, but I'm uncertain how to let that formatter run in parallel to the standard formatter
*Thread Reply:* @Kyle Bailey you can specify multiple formatters on the command line. Cucumber will send events to all of them. You shouldn't need to worry about what order they run in.
Hi -for v7 , the scenario.result.exception was removed from the HookScenarioResult (now ITestCaseHookParameter). Why was this? Is there a recommended way to get the exception from step failures? I coul duse setFunctionDefinitionWrapper but I'd rather avoid that.
*Thread Reply:* @Adam Merritt I believe it was removed because we changed the internal data structures as events were refactored to use cucumber-messages: https://github.com/cucumber/cucumber-js/blob/master/CHANGELOG.md#breaking-changes
What do you need scenario.result.exception for? Perhaps we can suggest an alternative approach?
*Thread Reply:* I'm using cucumber for UI automation testing and have an error type that will store the Dom structure as JSON when it throws. The problem is I want that piece (the UI interface) decoupled from Cucumber, so it wouldn't have access to the World
*Thread Reply:* If I use "Set definition function wrapper " then it's dependent on no other component overriding it
Does cucumber-pretty work with the new @cucumber/cucumber package? When I try to run with it ./node_modules/.bin/cucumber-js -f node_modules/cucumber-pretty
I get Error: Cannot find module 'cucumber' but running without cucumber-pretty is fine. Is there an alternative?
Works when I change the require inside cucumber-pretty. I suppose I should go bug the package maintainer 🙂
*Thread Reply:* it's already there https://github.com/kozhevnikov/cucumber-pretty/issues/14 🙂
Hi everyone. Is it possible to call features in the command line whilst passing a variable to them?
I’m trying to write an npmjs package to provide our developers with pre-built steps so they only have to write the cucumber files. I’ve made node packages before, but not like this and I’m getting stuck repeatedly. Before working on making it… executable…? my first step has been to try to make a package that someone can require in their ./support/steps.js that will just provide all the steps. I’m bringing in the file locally with npm link and I’m getting Cannot set property 'World' of undefined. What other information can I give that could help get me closer to my goal?
Also, is there any point to doing this or should I try to jump straight to… whatever I need to jump to so that folks won’t need any .js files?
*Thread Reply:* 9 years ago I discovered that prebuilt step definitions are a bad idea: https://aslakhellesoy.com/post/11055981222/the-training-wheels-came-off
*Thread Reply:* I will read! I suspect I have a different use case than is normally in here.
*Thread Reply:* I really enjoyed that. Well written article and it brings up a lot of good points and makes me question if cucumber really is the solution we’re looking for. Do you have bandwidth for a full discussion in here, @Aslak Hellesøy?
*Thread Reply:* The point I’m trying to make in that article is that scenarios should reflect domain language and business rules. Not the user interface.
*Thread Reply:* It makes sense, and that’s why maybe another tool is better for us than cucumber - we’re testing interface, not domain/business rules.
*Thread Reply:* One of the problems is that we need humans to be able to write them.
*Thread Reply:* We need something that lets us write human sentences to test forms for correct behavior.
*Thread Reply:* So you may well have more success using a different tool. Related articles: https://cucumber.io/blog/collaboration/the-worlds-most-misunderstood-collaboration-tool/ and https://cucumber.io/blog/bdd/bdd-is-not-test-automation/
*Thread Reply:* You can do that with Cucumber, but your tests will be brittle, slow and hard to maintain
*Thread Reply:* Is there something else we can do that with that would be better?
*Thread Reply:* We’re basically doing regression testing, we just need humans to be able to write it, not coders.
*Thread Reply:* We’re working on putting out emergency court forms like stopping evictions and requesting help with domestic violence. Those forms have certain things about them that absolutely have to work for them to be safe for people to use them.
*Thread Reply:* We don’t have a ton of coders. We do have volunteers, most of them with legal experience (which doesn’t help much).
*Thread Reply:* Some tests aren’t just ‘click this button’ and ‘type this in’. We’re building a framework so that these can be more easily created and deployed. That is, all the pages that ask for names will be the same. That can let us build a step that fills in a name on a name page. We haven’t figured out how to abstract more than that without every form maker having to write code that they don’t have time to learn.
*Thread Reply:* I’d recommend trying out a declarative style rather than imperative. Ben Mabey’s original blog post is gone I think, but here is a riff on it: http://blog.nickcox.me/2012/12/17/refactoring-cucumber/
*Thread Reply:* We also want people to be able to re-use the tests we write, of course, which is why I’m trying to make a package.
*Thread Reply:* Note that a declarative approach is incompatible with pre-built step definitions, which tend to be imperative.
*Thread Reply:* I really recommend that step definitions are written, maintained and refactored by the same people who build the application.
*Thread Reply:* We’re teaching the volunteers to code, but they’re coding in python in a framework that simplifies a lot of what they do. They’re not ready to write files like “#spec/acceptance/forms/feedback_steps.rb”
*Thread Reply:* I understand that in an ideal world we’d have the money to hire more coders, but we don’t have that.
*Thread Reply:* I understand. I think you should try what you’re planning. It might work out, but just wanted to warn you of some common pitfalls.
*Thread Reply:* For sure, and these are really good points. I’m going to bring them up with the team and see what people think we can do about these. I can’t currently think how to account for them within our budget, but maybe someone else will have an idea.
So far the test writing has gone pretty well, but we’re copying the step code into every repo. No one can take advantage of updates very easily. The volunteers are not great at using github and it’s taking a lot of developer time to update the steps.js files, etc.
*Thread Reply:* Right now I’ve set aside time to learn how to make a package that can take care of some abstractions. No pressure, but is that something you have knowledge about and a discussion you have bandwidth for, @Aslak Hellesøy? I understand if you feel I’m just wasting your time. I can try to find answers somewhere else.
*Thread Reply:* We need to figure out something that can take pressure off of testing by hand. We have some forms that can take 30 - 45 min. to fill out [accurately by a human] (like the domestic abuse one).
*Thread Reply:* I'm afraid I don't have much time to help. I recommend you start an issue on GitHub with as much detail as possible. What you're trying to do might even require a change to Cucumber.js - I'm not sure.
*Thread Reply:* Ok, thanks. Do you have a sec to give me tips on how to improve my question so that it provides better context or is more clear?
*Thread Reply:* Also, just wanted to say I think it's great Cucumber is used for what you're working on!
*Thread Reply:* Thanks! So far it really has saved us a ton of time and let us re-focus on the users. Just need to make the ecosystem easier to expand on.
☝️ Would still appreciate help if someone sees the above and has some insights.
Got the tests package working, though not really in the way I want - the developer still needs a require in one of the scripts. The package also doesn’t have access to .env. I tried to put #!/usr/bin/env node at the top of index.js, but it didn’t help.
If someone has insights on how I could take all requirements scripts other than .feature out of there, I’d love to hear them. If not, I may make an issue on github if I can put together the time to do it.
Thanks for the insights so far!
Hi @Jeremy Lorino. I’m still stuck where I was at my last report. Not really sure what to look into next to make progress.
*Thread Reply:* This is the package: https://github.com/plocket/docassemble-cucumber
*Thread Reply:* So I as a developer would use this package?
And one of the main issues is not having env vars or config?
*Thread Reply:* I prefer to use https://www.npmjs.com/package/config over dotenv in a situation like this
*Thread Reply:* Let me pull it down and see if I can use it as a consumer
*Thread Reply:* Thanks. I’ll take a look at config. I’m still not sure how to get it so the developers don’t have to write any .js files, just .feature files.
*Thread Reply:* so i should be able to do this right?
const Framework = require("docassemble-cucumber");
console.log("Framework", Framework);
*Thread Reply:* I’m not sure you should be able to log anything, you just need to be able to use a .features file with it.
*Thread Reply:* Only opening the interview will work for you if you’re not visiting the right sight, though, so you might only be able to ‘start an interview at’
*Thread Reply:* well i assume i'd need a feature file specific to your tests cases ya?
*Thread Reply:* y’know what, there’s no reason you shouldn’t be able to run it with the test repo. Just a sec.
*Thread Reply:* Use the npmjs branch and don’t bother trying to do anything other than running the tests.
*Thread Reply:* Can’t be because the file’s not able to use them anymore.
*Thread Reply:* Just going to double check - you’re using the npmjs branch?
*Thread Reply:* ran
npm i
npm link docassemble-cucumber
npm run cucumber
*Thread Reply:* You at least confirmed it works on someone else’s environment. Other people are taking the weekend off for some crazy reason.
*Thread Reply:* Trying to get rid of as many files as I can to simplify the process for folks. I wanted to reduce the number of folders and put everything in features, but someone brought up our desire for unit tests in the future.
*Thread Reply:* Ideally developers would only have to write .feature files and there’d be as little setup as possible.
*Thread Reply:* wait whats diff between the main package and the published one?
*Thread Reply:* Yeah, except it doesn’t. I haven’t been able to get it to.
*Thread Reply:* I can see that providing ~the~ [that] link was misleading. Learning a lot about communication today.
*Thread Reply:* where is this?
Error: Cannot find module './interview-constants.js'
*Thread Reply:* Yeah, trying to get rid of those env vars, but you shouldn’t be trying to trigger them anyway for this part.
*Thread Reply:* you should probably package cucumber with your package
*Thread Reply:* I got recommended to only include it as a peer dependency. I guess I’ll put one vote for each so far, lol.
*Thread Reply:* before you do it all. do a npm i -g . inside your package
*Thread Reply:* i'm still running in ~/source/repos/docassemble-IntegratedTesting
*Thread Reply:* I’m a bit distracted with some kind of …memory leak? in my computer right now that makes it think my folders have a ton of files in them.
*Thread Reply:* i'm not sure how to tell cucumber where to look for the stesps
*Thread Reply:* I may not have to move the steps if I do what your code just did. I’ll have to try it after I figure out how to keep my computer from exploding.
*Thread Reply:* If you’re ever back on, @Jeremy Lorino, I’m trying to replicate your file and I’m not sure where to require the files for the package - scope.js, world.js, etc. Where does that happen?
*Thread Reply:* Other than that, I’m also curious about what’s going on there, but I can probably look that up myself.
*Thread Reply:* I think I may be using it closer to what was intended now and I’m getting:
Command failed: sh stuff/node_modules/.bin/cucumber-js tests/features/interactive.feature tests/features/observations.feature
stuff/node_modules/.bin/cucumber-js: line 3: syntax error near unexpected token `'../lib/cli/run.js''
stuff/node_modules/.bin/cucumber-js: line 3: `require('../lib/cli/run.js').default();'
*Thread Reply:* All my file did was pass through the list of files to cucumber-js
It requires a list of space delimited files
*Thread Reply:* So it needs the files from the package as well? [I’ll just try it out]
*Thread Reply:* I would have to see the code. Not at my computer right now.
Push a branch and link it.
*Thread Reply:* It’s pushed to main. I can always revert to an old commit at v2.
*Thread Reply:* Thanks for all your help. A friend had some time and we figured out I just need to add the main file as required in the package script just before naming the path to the features. This was the line: https://gist.github.com/plocket/55c0079784265ca2a06630cf489f20da
I think I can get rid of our .env needs for the non-executable stuff, so that also gets rid of a file we’d need people to add for this.
Bonjour! "Guys" is easily replaced with the more gender-neutral "Folks" or "All". We'd appreciate if you tried to use that. Thanks!
Hello, I'm trying to get access to my cucumber stacktrace, which is only displaying when I have the --publish tag on, in the browser. I would like to be able to see the stacktrace in my terminal (I don't want to publish everytime)
@Mona Ghassemi If the exception is thrown in asynchronous code (i.e. if your step definitions use promises or callbacks), then I don't think there is a way to make the stack trace include stack frames from Cucumber. This is a limitation of Node.js.
I'm surprised you're getting different stack traces in the HTML reports. Can you share a MCVE?
@tooky "test": "./node_modules/.bin/cucumber-js features/PublicApi/publicApi.feature -r steps --require-module @babel/register --require-module @babel/polyfill --format usage"
*Thread Reply:* I see you have --format usage set. I think this will show you which step definitions are used. Adding -b shouldn’t have any effect.
Are you seeing a table of steps or pass/fail reports?
*Thread Reply:* It's not the best format but it's the best I could find. I think the format I am used to was cucumber-pretty but I realized it's no longer compatible with the new package.
*Thread Reply:* @Mona Ghassemi --format usage doesn’t execute your scenarios so it won’t tell you if it is passing or failing. I think --format progress is what you are looking for.
*Thread Reply:* there is a pretty formatter available, but unfortunately it doesn’t suppor the latest version of cucumber https://github.com/kozhevnikov/cucumber-pretty/issues/14
*Thread Reply:* yes, I was asking about this not long ago and then I read the Github discussion 😞
*Thread Reply:* I don't like --format progress; it doesn't show my steps:
```..
1 scenario (1 passed) 2 steps (2 passed) 0m00.307s (executing steps: 0m00.303s)```
*Thread Reply:* Oh I see usage is going to be weird once I add more scenarios...
*Thread Reply:* yes --format progress will only show the steps on failed scenarios (if I remember correctly). But --format usage doesn’t actually run your scenarios so you won’t know if anything passes or fails.
At the moment I have fixed the code so I no longer have an error to get a stacktrace. Next time I'm working on this I'll let you guys know and try to provide an MCVE (I had to look it up 🙂 )
Bonjour! "Guys" is easily replaced with the more gender-neutral "Folks" or "All". We'd appreciate if you tried to use that. Thanks!
Hello, I'm trying to define cucumber parameters in a file as in this example: https://stackoverflow.com/questions/60758671/how-do-i-use-hooks-before-after-with-cucumber-js-tsflow
Currently I am getting this error:
TypeError: (0 , _cucumber.default) is not a function
at Object.<anonymous> (/Users/.../support/world.js:9:1)
*Thread Reply:* This is the code that line refers to: ```import setWorldConstructor from '@cucumber/cucumber' import setEnv from "../config/setEnv";
function CustomWorld() { this.ENV = setEnv() console.log(this.ENV) }
setWorldConstructor(CustomWorld) // <-- this is line 9```
*Thread Reply:* @Mona Ghassemi your import statement is incorrect. Try import { setWorldConstructor } from ‘@cucumber/cucumber’
*Thread Reply:* Also I believe I found the documentation but it wasn't helping with this error; I was a bit thrown off 🙂
*Thread Reply:* https://github.com/cucumber/cucumber-js/blob/master/features/profiles.feature for future reference in case anyone is looking at this
I have a file at my project root like this: ```const common = [ 'features/PublicApi/publicApi.feature', '--require-module @babel/register', '--require-module @babel/polyfill', '--require steps/**/.js', // Load step definitions '--require support/hooks.js', // Load hooks '--require support/world.js', // Load world '--format progress-bar', // Load custom formatter ].join(' ');
module.exports = { default: common };```
I am attempting to run command like this:
"test": "node -r dotenv/config ./node_modules/.bin/cucumber-js -p default",
Any pointers in the right direction would be appreciated! Also, any pointers as how to correctly set environment variables to use in test steps with World. I have used it in the past but I'm struggling a bit and not easily finding resources to explain it on the internet.
Hi - (Working with major 7) I'm getting type error when returning a string 'skipped' , but the docs still say I can do this
[12:45 PM] is this a bug with the type? [12:46 PM] https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/step_definitions.md#skipped-steps
*Thread Reply:* @Adam Merritt can you please share the full stack trace?
Hi I have to click on a link that is always generated by the system and is always different, in the DOM is just a. <a href> any ideas on how to reach my goal what is clicking on the link?
*Thread Reply:* @Balazs Mandel add an id or class to it so you can identify it more easily. Or use XPath.
*Thread Reply:* @Aslak Hellesøy yeah that was the solution thanks !!!
*Thread Reply:* That sounds like more of a webdriverIO question, not a cucumber question, but glad you got your answer!
Hello there! I'm searching for some help in cucumber-js, I recently upgrade from V5 to cucumber V7 to use the new feature of the tests reports. If I don't use the --publish option (to publish reports) it's working fine like before, but when I add it, I get an error at the end of the test, the error seem to come from a file in a node_modules. When I comment the code in that file, everything is working fine, no more errors, but it's not a pleasing solution because I have to comment that file every time I do a npm i .. Do you have any idea about how I can resolve that ?
*Thread Reply:* The error is that one: ``` scenarios (7 passed) 23 steps (23 passed) 0m20.580s (executing steps: 0m20.548s) events.js:109 throw new ERRINVALIDARG_TYPE('listener', 'Function', listener); ^
TypeError [ERRINVALIDARGTYPE]: The "listener" argument must be of type function. Received an instance of Object at checkListener (events.js:109:11) at ClientRequest.once (events.js:431:3) at new ClientRequest (httpclient.js:194:10) at Object.request (https.js:314:10) at Object.request (/home/florent/app/nodemodules/agent-base/patch-core.js:25:22) { code: 'ERRINVALIDARG_TYPE', CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {} ], } npm ERR! code ELIFECYCLE npm ERR! errno 1```
And the file I commented is patch-core in agent-base module
```'use strict'; const url = require('url'); const https = require('https');
/**
* This currently needs to be applied to all Node.js versions
* in order to determine if the req is an HTTP or HTTPS request.
*
* There is currently no PR attempting to move this property upstream.
**/
// const patchMarker = "agentbasehttpsrequestpatched";
// if (!https.request[patchMarker]) {
// https.request = (function(request) {
// return function(options, cb) {
// let options;
// if (typeof _options === 'string') {
// options = url.parse(options);
// } else {
// options = Object.assign({}, _options);
// }
// if (null == options.port) {
// options.port = 443;
// }
// options.secureEndpoint = true;
// return request.call(https, options, cb);
// };
// })(https.request);
// https.request[patchMarker] = true;
// }
// /**
// * This is needed for Node.js >= 9.0.0 to make sure https.get() uses the
// * patched https.request().
// *
// * Ref: https://github.com/nodejs/node/commit/5118f31
// **/
// https.get = function (url, _options, cb) {
// let options;
// if (typeof _url === 'string' && _options && typeof _options !== 'function') {
// options = Object.assign({}, url.parse(url), options);
// } else if (!options && !cb) {
// options = _url;
// } else if (!cb) {
// options = _url;
// cb = _options;
// }
// const req = https.request(options, cb); // req.end(); // return req; // };```
*Thread Reply:* could you create an issue on cucumber-js with the info / file ref and a reproducible scenario.
*Thread Reply:* ok, I'll try to find a minimal reproducible example
*Thread Reply:* @luke I find a way to reproduce this with a minimal amount of code: clone: https://github.com/Florent-Bouisset/testCucumberReports.git npm install, and then run npm run cucumber => it should work then npm run cucumberReport => there is an error and the report is not published
*Thread Reply:* can you push that up to the issue tracker with the relevant links and we can take a look.
*Thread Reply:* @luke before creating an issue I look if there was a problem with the tool puppeteer that I am using for doing e2e test, and I found out that if I upgrade puppeteer to the last version, I don't have the pblm anymore, so it's solved 😛 thx
*Thread Reply:* Yes that's what I would have suggested first when you are getting such issues.
*Thread Reply:* yes, they were not up to date because the new updates introduces breaking change that broke some parts of the app..
*Thread Reply:* Yeah breaking changes are a whole project to fix 🙂
*Thread Reply:* So is this still a problem after upgrading @Florent Bouisset ?
I'm scratching my head here... How can null be compatible with ReadonlyArray?
Hi, I want before run cucumber scenarios get this scenario steps and i have a test result json file, i will add step of running scenario into this json file but now i can't get steps, can you help me?
Hi everyone..
Have someone else experiencing the --format snippet running more than once, depending on how many Examples are defined in the gherkin file?
*Thread Reply:* To be more clear, I have a feature file like the following:
```Feature: Calculator
Scenario: Test Given I have number <n1> When I sum with <n2> or multiply by <n3> Then Result should be <result>
Examples:
| n1 | n2 | n3 | result |
| 1 | 2 | 3 | 3 |
| 2 | 4 | 3 | 6 | ```
*Thread Reply:* when I run cucumber-js --format snippets the result is two identical snippet for each sentence (because of the two executed scenarios)
*Thread Reply:* It should be: Scenario Outline: not Scenario:
Let me know if that helps.
Ref: https://cucumber.io/docs/gherkin/reference/
*Thread Reply:* I've already tried with Scenario Outline.. Same behaviour
*Thread Reply:* Hm, I can't really play around with it. I think Scenario Outlines are broken in that RC or at least, I can't get it to work as it doesn't recognise the Outline keyword.
But even on Master branch I am having issues with Scenario Outlines - though on master I get a different issue - the steps are not being recognised. 😞
*Thread Reply:* Thanks @Kārlis Amoliņš.. so, should I create an issue on github?
*Thread Reply:* Based on what someone else wrote - Outlines should be working so trying to make it work in a fresh repo, will let you know if that works - and if it does, will try to repro the issue you saw
*Thread Reply:* I think I was somewhat off (misremembered what snippets does.
I think the behaviour you see is somewhat right. snippets print out definition for each undefined step.
So from the perspective of Cucumber it is doing what it should even though there is no practical benefit to it.
*Thread Reply:* Yes, but maybe for the snippet generation purpose it would be very useful to produce just a single snippet per sentence
*Thread Reply:* @Kārlis Amoliņš Scenario is interchangeable with Scenario Outline since a while now...
*Thread Reply:* Not sure why you think Scenario Outline is broken?
*Thread Reply:* @Aslak Hellesøy Hmmm, interesting.. Not sure why I was so convinced about them not being interchangeable. Thanks for pointing that out and apologies for spreading misinformation!
And I managed to get Scenario Outlines to work at a later point, I think my environment was messed up. 😓
Field f = scenario.getClass().getDeclaredField("testCase");
This is not useable anymore now cucumber with java and i want get scenario steps how can i use this with new cucumber version?
*Thread Reply:* Hello. You should probably ask your question in <#C5YHPPJMP|help-cucumber-jvm> since it is Java specific
Hi friends! I've posted an issue here: https://github.com/cucumber/cucumber-js/issues/1461 Does anyone have any workarounds?
*Thread Reply:* Somewhat related question - are you able to run Scenario Outlines at all when using the RC?
*Thread Reply:* I'm not familiar with "RC"? But i'm currently able to run them.
*Thread Reply:* Apologies, by RC I meant Release Candidate (which is the latest released version of @cucumber/cucumber) and my question was, are you able to run Scenario outlines when using latest version of @cucumber/cucumber ?
*Thread Reply:* I tried to assist someone earlier today/yesterday, but I couldn't get Scenario Outlines to work at all when using the latest version of cucumber 7.0.0-rc.0
*Thread Reply:* yes, it is running the scenario outlines just fine.
Of course I needed to modify my step_defs to require @cucumber/cucumber instead of just cucumber
*Thread Reply:* the only problem is as stated above, it seems to have forgotten how to find overloaded functions
*Thread Reply:* Out of curiosity, do you still have @types/cucumber in your repo?
There is Sylius https://github.com/Sylius/Sylius/tree/master/features (this is written in PHP)
I’m developing a package that uses cucumberjs. Right now, I’m having to bump the npm version every [time] I change anything, like when I fix a typo. I tried linking the package locally a while ago and got some error about world. Does someone know how to solve that so I can link locally instead of using npm as a go-between?
*Thread Reply:* Yeah, I think I know what this is.
When you npm link your library, you introduce a problem where your libary and the host project are using different instances of cucumber (each from their own node_modules dir) which causes failure.
There is a bit of info and some suggestions here https://github.com/cucumber/cucumber-js/issues/1146. My solution on a few projects has been to use the "import-cwd" package (https://www.npmjs.com/package/import-cwd), like this:
const importCwd = require("import-cwd");
const {Given, When, Then} = importCwd("cucumber");
That way even when linked you're always using the host project's cucumber-js instance and all should be well. Hope this helps.
When I use puppeteer to download a file, cucumber does not finish, it just hangs. I found this way to detect about when the the file will be downloaded, I don’t always want to close the browser when the download completes, I just want cucumber to be able to finish at the end. What are some resources that can point me in the right direction to solve this?
Hi everybody ! I'm setting up a project with cucumber-js and typescript and I am facing some problems regarding the this as function context w.r.t the cucumber's World.
Given the following world
```# world.ts
import { World, setWorldConstructor } from 'cucumber';
function MyWorld(this: World) { this.worldParameter = 'hello'; }
setWorldConstructor(MyWorld);
I defined a step_def.ts as follows:
# step_def.ts
import { Given, When, Then, World } from 'cucumber';
function foo(val: string): Promise<any> {
const value = ${this.worldParameter}_${val}_${this.worldParameter};
console.log(value);
return Promise.resolve('success');
}
Given(/^STEP WITH 1 PARAMETER$/, foo);
This is not fine to Typescript because of [TSError: 'this' implicitly has type 'any' because it does not have a type annotation.ts(2683)]
So, I added the `this: any` as first parameter of the foo function and it became like as follows:
# step_def.ts
import { Given, When, Then, World } from 'cucumber';
function foo(this: any, val: string): Promise<any> {
const value = ${this.worldParameter}_${val}_${this.worldParameter};
console.log(value);
return Promise.resolve('success');
}
Given(/^STEP WITH 1 PARAMETER$/, foo);
This worked ! However, if I want to share `foo` code across many steps, I can write something like this:
Given(/^STEP WITH 2 PARAMETERS$/, async function (val1: string, val2: string) {
await foo(val1);
await foo(val2);
});
and here I face the problem with this parameter..I tried also to write it in different way, such as:
Given(/^STEP WITH 2 PARAMETERS$/, async function (this: any, val1: string, val2: string) {
await foo(this, val1);
await foo(this, val2);
});```
but it didn't work. Can anyone give me some hint please?
*Thread Reply:* I'm just curious what packages are you using to run cucumber with ts? Last time I checked, I saw the ts cucumber package (not sure exactly what it was called but I can check) was still using old cucumber package (prior to the re-name) so I was not able to transition to ts at that time. I'd appreciate if you could share your package.json set-up.
*Thread Reply:* Hi, sure, I'am using:
"@types/cucumber": "6.0.1",
"cucumber": "6.0.5",
"ts-node": "9.0.0",
my tsconfig is the following:
{
"compilerOptions": {
"target": "ES2019",
"module": "commonjs",
"declaration": true,
"sourceMap": true,
"strict": true,
"strictBindCallApply": false,
"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"strictPropertyInitialization": false
}
}
and the script I use to execute cucumber is
npx cucumber-js --require-module ts-node/register --require 'features/****/**.ts' features/****/**.feature
*Thread Reply:* Ah, looks like indeed you are using a prior version of cucumber. We're using "@cucumber/cucumber": "^7.0.0-rc.0". Was excited about the reporting feature and this was a new project. I was first attempting the setup using this guide: https://dev.to/denolfe/cucumber-js-with-typescript-44cg and I believe it was indeed @types/cucumber that was using the old dependency, and it seems it has not been updated recently: https://www.npmjs.com/package/@types/cucumber 😞
*Thread Reply:* But I've also heard typescript is a lot of overhead as well so 🤷
Hey @Roberto Zen
I think you’re pretty close; there’s a couple of different ways you could solve it. When you add this: any as the first parameter to a function, it doesn’t actually end up being a parameter in the JS, it’s just compiler advice. So the structure of foo comes out as per your first example, with just one parameter. If you want to control what the value of this is within the function, you could change the way you call it to use Function.prototype.call , like this:
await foo.call(this, val1);
Alternatively, you could leave your usage as it is, and make the world a normal parameter in your function - so rewrite it to something like:
function foo(world: any, val: string): Promise<any> {
const value = `${world.worldParameter}_${val}_${world.worldParameter}`;
console.log(value);
return Promise.resolve('success');
}
(I would argue that second one is a bit clearer, FWIW.)
Finally, for a different angle again, you could always make your World a class and make foo a method on it, so you can just call it from each step.
Hope this helps!
Hi @David Goss thank you for the reply. I tried the second solution you wrote, thus:
function foo(world: any, val: string): Promise<any> {
const value = `${world.worldParameter}_${val}_${world.worldParameter}`;
console.log(value);
return Promise.resolve('success');
}
However, when I write
Given(/^STEP WITH 1 PARAMETER$/, foo);
I see that world is set to the parameter get from the step, while the val is a function (callback I immagine)
Thus world becomes a real parameter, and it is no longer the cucumber's World
Ah sorry, I didn’t pick up originally that you want to use the function directly as a step function - I would say just:
Given(/^STEP WITH 1 PARAMETER$/, async function(this: any, val: string) {
await foo(this, val);
});
So your foo function becomes a utility but all the steps are still their own function literal.
Getting jar file issue.... that its not able to find features file in that
@vishu handa I think you want to post in <#C5YHPPJMP|help-cucumber-jvm>, this channel is for the JavaScript version
Having blue murder with webdriverio and cucumber 😭
```Feature: Login
Scenario Outline: As a user, I recieve an error message when using invalid credentials to log into the application
Given I am on the login page
When I login with <username> and <password>
Then I should see an error message saying <message>
Examples:
| username | password | message |
| CD2 Team | empty_string | The password field is empty. |
| empty_string | 4y94hr4uejfhekj | The username field is empty. |
Scenario: As a user, I can login
Given I am on the login page
When I login as an admin
Then I should be on the admin dashboard page```
The above works, but I get odd messages like
> [20200:20212:1130/132632.334:ERROR:deviceeventlogimpl.cc(211)] [13:26:32.333] USB: usbdevicehandlewin.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F) Also the reporting I get is unexpected...
> Spec Files: 1 passed, 1 total (100% completed) in 00:00:15 The reporting I would like would be something more like a Jest test
``` PASS e2e/features/login.feature (25.59 s) As a user, I recieve an error message when using invalid credentials to log into the application √ Missing Username √ Missing Password As a user, I can login √ as an admin (28 ms)
Test Suites: 1 passed, 1 total Tests: 3 passed, 3 total Snapshots: 3 passed, 3 total Time: 32.38 s Ran all test suites.``` Does anyone know if there is something out-of-the-box that can pair webdriverio and cucumber with this type of reporting, silencing the noise?
I believe it's "@wdio/cucumber-framework" which according to my package lock file uses the official nodejs cucumber package
Right I got it...
npm install @wdio/dot-reporter --save-dev then add 'spec' to reporters
Hi All, I'm in the process of upgrading cucumber from 5.1.0 to 7.0.0-rc.0 and the cucumber.getTestCasesFromFilesystem routine seems to have been moved. Is there a new approach for getting the test cases from filesystem?
Opened issue here: https://github.com/cucumber/cucumber-js/issues/1489 around getTestCasesFromFilesystem Thanks for response @David Goss
Hello, Tool Details: Cypress Cucumber Chai multi-cucumber-report I am facing issue Feature file connection with StepDef. for example : Unable to user feature A’s stepDef into feature B.
Hi
I’m using cucumber.js 7.0.0-rc.0 and I want to be able to filter out scenarios based on the availability of back-end data, that is very fluid in nature.
With cucumber-jvm and TestNG I was able to setup a filter that removed individual scenarios based on the required data not being available prior to any scenarios being run. This worked perfectly and did not require and changes to cucumber-jvm of TestNG Now i’m trying to migrate this capability to a test framework built with cucumber.js and so far i have not found a solution that does not require any changes to cucumber code base.. Does anyone have any ideas about how i might be able to do this? Thanks in advance.
Hi Michael, would fixtures or dummy data that is always present not be the best way?
Hi @Lewis Cowles, My test framework running against a real systems and the resource i need is used by other groups within the enterprise. through their tests, the resource required sometimes gets clobbered or removed entirely. so my Java solution was to test for the data’s existence, and if it doesn’t exist, the framework removes the scenario/pickle before the tests start. I want to migrate this capability to my new typescript solution.
If it's functioning as a test and removal triggers a skip, it sounds like engineering in false confidence.
You do have the ability to run code before test suites, scenarios, steps, and I would likely change strategy to do that rather than conditionally skip.
It's up to you, but I'd seriously re-consider this approach, unless it's skipping features that are switched off, and even then, I'd suggests shipping / deploying those with the feature, rather than conditionally skipping.
Just an idea of how to approach alternatively.
@Lewis Cowles Thanks, I should add that the filter is driven by the first given step in each scenario. if the given fails, which is essentially the prerequisite to running a test scenario, i want to skip the test scenario entirely because the prerequisite failure is really a false failure, because nothing of interest can be tested or proven. so my solution is a pre-check for prerequisites, if that fails, skip the scenario.
cucumber-jvm in my java solution which removes scenarios (ie., cucumber collects all the tagged scenarios, and then the pre-check removes any where the prerequisites is not available), doesn’t even know anything was skipped at all. TestNg offers this
public abstract class AbstractTestNGCucumberTests {}
and it has this method which i wrap with my filter
exactly what i want. reports summarizes which prerequisites are missing. All this occurs before any tests are actually run.
i’ve been exploring cucumber/lib/cli/index.js as a possible way to get the pickles and filter them. but it feels wrong.
Hi everyone, i’ve been looking for a way to dynamically skip an entire scenario . I worked out a cucumber-jvm approach that works perfectly, but for cucumber.js i’m at a loss. is there a way to do that? Thanks
so in ruby there is one as is in java. I imagine the same one must exist.
Inside your world (hooks), try doing something like skip_this_scenario I appreciate this is a guess. As I don't code the js one. But it definitely "should" exist. If it doesn't let us know.
If there's a way to dynamically get the available functions in js when you're in the hooks try dumping them to the console.
Thanks, i’ll give that a look, i explained my java solution on December 6th and 9th above, its based on how the TestNG runner class AbstractTestNGCucumberTest provides a list of scenarios.
@luke i see the skip_this_scenario in ruby, but nothing like that appears in javascript. it would be a nice feature. Thanks for the clues.
Hi everyone, i’ve looked at GherkinDocumentWalker from gherkin-utils to filter out a scenario based on availability of data. so i can see the scenario.gherkinDocument adjusted in the Before hook, but the scenario that i filter is still executed. is the GherkinDocumentWalker a suitable tool? i expect i haven’t used the filtered gherkinDocument properly, it looks like the filtering is too late. Has anybody out there experience with this, and who can tell me what i’m doing wrong? thanks
I’m using Cypress/Cucumber/Typescript and looking for a reporter which can generate reports with attached screenshots, text, maybe some files, etc. Any help will be greatly appreciated
Did anyone use Allure Cypress plugin to generate Cucumber?cypress reports. I’l looking for simple example because the one on the site is huge and not easy to follow. Any help will be greatly appreciated
*Thread Reply:* A SDET that attends a local meetup I attend shared https://github.com/thomaschaplin/webdriverio-template which got me down a few rabbit holes
I am looking for some help for cucumber and jest. The context is: we write our api-specs with jest but still generate the nice cucumber HTML reports. There are 2 packages solving the test part but only one quite old version of one of them supports the reports.
Is this the right channel for this context?
*Thread Reply:* I am using jest-cucumber but it does not really supporting reporting. They had one version (one year old) which had the reporting included but the maintainer is not happy with it and haven't included it in any other version. Now I am stuck, cannot update and will wake up with security leaks 😞
*Thread Reply:* so the question is if you have an idea how and with what I could write jest tests but have cucumber features and reports?
*Thread Reply:* Hi @Krisztina Hirth, I’d like to understand more about the motivation behind using jest-cucumber. Reading between the lines, it sounds like you aren’t that bothered about writing your specs in Gherkin - you write them in jest - but just want good reporting, is that fair?
With the release of cucumber-js 7.0.0 today, a run of cucumber generates standard messages that can be consumed by a formatter (including our own html formatter). So in theory you (or, the maintainer of jest-cucumber) could generate those messages from jest and use the same formatter - would be a bit of work involved but I could give some pointers.
*Thread Reply:* Happy New Year everybody, sorry @David Goss for the silence, I had holiday and I had to reduce my amount of communication 🙂
*Thread Reply:* After reading your question I realized that it was an error to not start with cucumber-js from the beginning on
*Thread Reply:* I started to rewrite the tests today afternoon and I still would have a couple of questions:
*Thread Reply:* The first one: is there a possibility to configure the call via a config object? My npm command is 2 rows long already 🙄
*Thread Reply:* yep you can define “profiles” in a cucumber.js file in your project, see https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#profiles
*Thread Reply:* simple example: https://github.com/davidjgoss/cucumber-puppeteer-typescript-starter/blob/master/cucumber.js
*Thread Reply:* an example like this would be very helpful in the docs
*Thread Reply:* agreed! i have a few things to do in the docs so will add that
*Thread Reply:* Last question: I read that the JSON reports are deprecated
*Thread Reply:* I tried the current format and it is cool but it can be nicer :)
*Thread Reply:* Do you know the html-cucumber-reporter (or similar)?
*Thread Reply:* so that one and others use the (deprecated) JSON formatter output, is that what you mean?
*Thread Reply:* This is what I use at the moment but it needs json as entry file.
*Thread Reply:* The question is: what is your recommendation to be used instead of json?
*Thread Reply:* if you are not using it is ok, I will check tomorrow
*Thread Reply:* the JSON formatter is deprecated but wont be removed until 8.0.0 which is probably some way off, so it’s fine to use for now. the core team have also written libraries for converting between the JSON format and the new messages protocol, meaning formatters like that should be able to refactor so they can tae the new messages as input without much difficulty before 8.0.0
*Thread Reply:* in the meantime it would be good to get your feedback on the built in html formatter. it’s quite new but now the infrastructure is in place so i think it could be iterated on quite well
*Thread Reply:* I think it is cool, much more informative as the old one 🙂
*Thread Reply:* I am on my private laptop now but tomorrow or the day after I will create some screenshots and then I can show you, what I'm missing if you would like :)
*Thread Reply:* So, I'm back 🙂
I migrated almost all my tests (50 scenarios). Regarding the reports: this is how the html-report looks like (but maybe your know this already, it is shown here https://www.npmjs.com/package/cucumber-html-reporter)
*Thread Reply:* I tried to use the ndjson-file but unfortunately didn't work:
⚠️ 😞 Unable to parse cucumberjs output into json: '%s' ./reports/cucumber.ndjson SyntaxError: ./reports/cucumber.ndjson: Unexpected token { in JSON at position 217
*Thread Reply:* Question 1: I saw that you are using it. What are you doing with it?
*Thread Reply:* Generally there are a few differences: • in the cucumber-html-report the scenarios are displayed, the steps are collapsed, in 2 columns on the page • in the cucumber.js report the files are listed and collapsed if green. This means for me that in this case the report is not intended as a documentation but as a regression testing tool • the cucumber-html report has that nice pie chart showing the overview. This is really nice but it is surely more a nice2have
*Thread Reply:* That's it regarding the reports. the cucumber-html-report is really nice and I will keep it until the json-format still exists but I will switch afterwards to the html-format.
*Thread Reply:* Now to the CustomWorld: I tried it today but it didn't work. When calling this in another file it was an empty object. I tried different filenames but it didn't help.
```[11:46] // file world.js or CustomWorld.js
const { setWorldConstructor } = require('@cucumber/cucumber');
const props = { insuranceOption: null };
class CustomWorld { constructor() { this.variable = props; }
setInsuranceOption(option) {
props.insuranceOption = option === 'add';
this.variable = {
...props
};
}
}
setWorldConstructor(CustomWorld);
// support file When(/^I choose to (add|not add) an additional travel insurance$/, async (option) => { console.log(this); this.setInsuranceOption(option); }); // error: TypeError: this.setInsuranceOption is not a function at CustomWorld.When (/home/``` What do I miss?
*Thread Reply:* > Question 1: I saw that you are using it. What are you doing with it?
You mean what am I doing with the NDJSON? Those messages is used as the input to the built-in HTML formatter (internally the html formatter option just pipes them through directly to save you doing it). Long term the idea is that most/all formatters use those messages as the input, meaning they could be common across all cucumber implementations.
*Thread Reply:* > the cucumber-html report has that nice pie chart showing the overview. This is really nice but it is surely more a nice2have Agree it's a nice to have, although the underlying desire for a ratio/percentage of pass:fail is interesting.
*Thread Reply:* The way you've set your custom world up is fine (though you may want to take the options argument to the constructor and call super(options) with it, so that you still get the attach function etc.
*Thread Reply:* The problem is with the step definition - you have an arrow function there, but it needs to be a regular function literal instead, like:
When(/^I choose to (add|not add) an additional travel insurance$/, async function(option) {
console.log(this);
this.setInsuranceOption(option);
});
(More about why here https://github.com/cucumber/cucumber-js/blob/master/docs/faq.md#the-world-instance-isnt-available-in-my-hooks-or-step-definitions.)
*Thread Reply:* I finished the migration and I am very satisfied (I ask myself why I even started with the jest-cucumber package 🤔 ) The custom world works very well too. Thanks a lot for your help!!
One last feedback to get an easier usability of the lib: I think a small hint or a few examples how to write the tests with chai.js would be helpful.
~cool~ 🙂 ~Would you like to know what it is all about (should I write it here) or rather directly?~ solved :)
When I try to implement my own timeout (as described here) and the tests fail, the tests finish (I see how many scenarios passed and failed), but the process never exists. At least, it doesn’t exit with a rejection. I haven’t yet gotten a completely passed test. What am I doing wrong here: https://github.com/plocket/docassemble-cucumber/blob/var_table/lib/steps.js#L183
*Thread Reply:* I think I’m mistaken. Sometimes it exits and sometimes it doesn’t. I haven’t yet figured out all the context, but I know that when the setTimeout rejects, the process does exit.
*Thread Reply:* Wrong again - it does finish, it just… takes a heck of a long time…?
For those who miss the obvious as much as I do, your custom world constructor can use attach, log, parameters:
Welp, apparently attach isn’t great for reporting stuff in the log after the test has run. Never used a reporter before. Does someone have hints about how to log this stuff right after the test results have logged?
*Thread Reply:* log is now available in 7.0.0
That and attach are really about providing data to formatters. Do you just want to output something to the console?
*Thread Reply:* Yes, to the console. People on our team, me included, find it really annoying to download files from github to see the report and we don’t have resources at the moment to set up some kind of reporting page.
*Thread Reply:* formatters are for building reports (or similar) with the output of a test run
*Thread Reply:* depending on how much and how big, you could just console.log
*Thread Reply:* Thanks. We wanted it to appear after the cucumber test report, but that part isn’t that important, so maybe we’ll stick with console.log. A formatter might be a stretch goal.
I guess I want to report in some way, but I’d rather do it right there in the console…
I tried attach in my After step anyway, to see if I could construct something useful and it didn’t do anything at all.
Cucumber.js 7.0.0 is out!!! • https://github.com/cucumber/cucumber-js/blob/master/CHANGELOG.md#700-2020-12-21 • https://www.npmjs.com/package/@cucumber/cucumber
*Thread Reply:* This is very exciting. Thanks for all the hard work!
i don't suppose the changes could cause cucumber to create/try to require an 'index.js' file in the cwd() ?
Our project doesn't have this file yet it's now throwing an error in the require stack
*Thread Reply:* Not something I’d expect, no - would you mind creating an issue under https://github.com/cucumber/cucumber-js/issues with some more details (ideally a little project where we can reproduce it) and I’ll take a look
Hi everyone! I’m having an issue with cucumber-js 7.0.0, where in both the new HTML reporter and the reports published to reports.cucumber.io I can’t attach a screenshot because I’m told the image isn’t base64 encoded.
The code I’m using is pretty much identical to the example given in the Cucumber docs:
await driver.takeScreenshot().then(function (screenShot) {
world.attach(screenShot, 'image/png')
})
I previously used the third party cucumber-html-reporter to generate HTML reports and the above code works fine there. Does anyone know what I could be doing wrong?
*Thread Reply:* Sorry for the late reply @Jim Trenowden
I think the docs are at odds with the reality here. If you pass a buffer or stream as the data (first arg) it will be base64 encoded, but if you pass a string it will be assumed to be the content type you declare (i.e. not base64 encoded). That leaves us without a way to attach directly from webdriver at present since it's returning a base64 encoded string (as opposed to say puppeteer which will give you a buffer).
I'm going to raise on GitHub and try to get it addressed. In the meantime I think you could (kind of awkwardly) work around it by decoding the base64 string (I know), like:
await driver.takeScreenshot().then(function (screenShot) {
world.attach(new Buffer(screenshot, 'base64'), 'image/png')
})
*Thread Reply:* Sorry, just seen your reply. That’s very helpful, thanks. Good to know it’s not just me!
Sorry. I was posting in the wrong help channel so reposting here:
I’m using cucumber-js 7 with typescript, and I always get some unknown error:
TypeError: Cannot read property 'line' of undefined
at Object.parseTestCaseAttempt (<long-path>/node_modules/@cucumber/cucumber/src/formatter/helpers/test_case_attempt_parser.ts:149:67)
Any idea what can be the issue?
*Thread Reply:* Are you using a custom formatter?
Are you able to link to a minimal repro somewhere public?
Hello! one question regarding v7 migration... is it possible that now is mandatory to pass the this: World as a parameter of the step definition?
*Thread Reply:* it is not mandatory per se from a runtime perspective, but it is necessary to make the compiler happy if you access anything on this in your step definition (and you use typescript).
*Thread Reply:* aham.. I see. I forgot to mention that Im using Typescript, yes. But in the the previous version it wasn't necessary...
*Thread Reply:* what do you mean by "it was not necessary"? do you get an error that was not there in previous versions, when you don't define it?
*Thread Reply:* With the previous version if I didnt pass the this: World as a parameter it worked fine. I could use this.foo within the step definition without any problem.
But now, it says the following:
error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
and
When(/^the {string} foo bar tap$/, async function (type: string) {
~~~~~
An outer value of 'this' is shadowed by this container.
*Thread Reply:* I gonna check if adding the parameter this: World it solves the issue
Hello! This might have been answered earlier but does anyone know how I could store the output summary of a Cucumber run after all scenarios have been executed and store it into a variable?
41 scenarios (39 passed, 2 failed)
394 steps (367 passed, 25 skipped, 2 failed)
34m18.053s
do you mean the exit code>? Or specifically that string you've quoted there.
*Thread Reply:* I mean the metrics from any test run (number of scenarios failed, passed, duration etc..)
*Thread Reply:* ah oki sorry. Good question I'm not 100% sure. I do know this kind of thing should be in the messages so if you're using the new-er versions it should be obtainable somehow.
*Thread Reply:* yeah we aggregate this from the standard messages emitted when cucumber runs
*Thread Reply:* if you look at the code for the summary formatter, you should be able to follow how it's doing it, and you could do something similar in a custom formatter
https://github.com/cucumber/cucumber-js/blob/master/src/formatter/summary_formatter.ts
Does anyone else think it would be useful to be able to pass additional arguments to setWorldConstructor(). This signature specifically:
setWorldConstructor( class, args[])
An array of arguments to be passed to each new world instance. Things like config arrays or the like which would otherwise need to be global.
Hello! I'm newbie to cucumber and js. Does anyone recommend the assertion package other than "assert"? Cucumber recommends the built-in "assert", however, I just wonder there exists more fitting package with Cucumber.
*Thread Reply:* Chai is popular: https://www.chaijs.com/
*Thread Reply:* I also use Chai, but I'm testing webpages and I find that often it's useful to just keep retrying the action until the step times out. For example, if I expect to see a value in an element as the result of an ajax call it's more stable to repeatedly look at the element at 50 millisecond intervals to account for load lag than do a flat assertion.
*Thread Reply:* Hmm, yes assertions can lead to some unwanted early fails. I learned about them a bit later in my automation journey and then wanted to use them everywhere, but now I know that in fact navigating to a page and finding an element actually counts as an (implicit) assertion (if you found what you were looking for, you're on the right page).
*Thread Reply:* At the end of the day, Cucumber is looking for a thrown and uncaught error and will stop the test when that happens. That's all that's really needed. It is often useful to catch Puppeteer/Selenium errors, which often have cryptic error message text, and rethrow them with a message that will be clear to whoever is reading Cucumber's test output.
*Thread Reply:* Assertion libraries are one way to do this very quickly, but not the only way.
*Thread Reply:* @Michael Morris Oh, yes. I also have experienced inconvenience in adding timeout to assertion with assertion libraries. Thank you! I need to consider it again.
Followup to the above - allowances would need to be made for command line parameters passed to world.
setWorldConstructor( class, params, args[])
Hello. I’m using cypress-cucumber-preprocessor and have issues/problems attaching on-demand screenshots to json report files in order to generate final HTML report. Can somebody suggest a solution?
*Thread Reply:* Can you post more detail about your issue? Maybe put the code up on GitHub?
*Thread Reply:* @David Goss cypress-cucumber-prepocessor generates json report file and also screenshot of errors and on demand in a separate folder. You can the use Jenkins Cucumber plugin to see report with CSS added. There will be no screenshots attached to it unless you embed those screenshots into those json file(s)
*Thread Reply:* well, I do use both from above. But I didn’t find a reliable solution to embed on-demand screenshots into json files
Is there any sort of cucumber blogging page were we can share things we've figured out?
*Thread Reply:* @Jo Laing what’s the process these days for community blog contributions? Can you help Michael out?
*Thread Reply:* @Michael Morris I don't know if we do that sort of thing anymore, but if you PM me what it is, maybe it's something I can include in the community newsletter.
*Thread Reply:* @Michael Morris Do you have the content ready in a doc? If so, you can post it in the <#C5YEEHG1E|recommended-media> channel for now and as Tracey mentioned above, it's maybe something we can include in the community newsletter too? I'd like to be able to offer up a place on cucumber.io for community blog contributions and have started looking at how to make that happen. Hope that helps a bit for now! 🙂
Specifically, I recently added an event emitter to my testing system since Cucumber.js doesn't ship with one to keep it's API consistent with the other languages.
Some examples of them are: https://cucumber.io/blog/
I personally think this one is the best one 🙂 https://cucumber.io/blog/open-source/tweaking-cucumber-rubys-auto-loader/
Cool. Yeah, the article I have in mind is in the same vein - but in this case leveraging Node.js' inbuilt EventEmitter class.
hi, Using cucumber-js@7 with emitting messages, is there a way to generate the html report from multiple files and same format as it was with cucumber-html-formatter?
So as in you ran say job X generating messages I then you ....
ran job Y generating messages II ran job Z generating messages III
And now you want one report from messages [I,II,III]
?
*Thread Reply:* yes. I am running different jobs on ci and then I collect all outputs and would like to generate a single report. Works well with cucumber6
Can the --retry and --fail-fast flags be used together to get the test to fail if a scenario runs out of retries?
*Thread Reply:* Good question - we don't seem to have any coverage or documentation of the interplay between --retry and --fail-fast but I would say yes, I think if you have both it should exhaust the retry attempts for a scenario and then fail fast (as opposed to disregarding the retry).
Okay, so I have an automation repo that is using cucumberjs. My world.js file has gotten rather large and I’m trying to divide it up so it is easier to organize. I’ve tried to dividing into files and combining it via the prototype -
// features/support/world.js
const foo = require(‘./foo.js’);
class customWorldObject {
bar(number) {
//do stuff;
}
}
customWorldObject.prototype.foo = foo;
setWorldConstructor(customWorldObject);
but later in in the step functions
// features/support/steps.js
const { Given, When, Then } = require(“@cucumber/cucumber”);
const assert = require(“assert”).strict;
When(“I increment the variable by {int}“, async function (number) {
this.bar(number);
});
When(“the variable should blah blah blah”, async function() {
this.foo();
});
When I run this puppy, it doesn’t seem the added function
TypeError: this.foo is not a function
So how can I correctly break the cucumberjs world object into separate files?
*Thread Reply:* I wrote this method for this problem.
applyTraits: (klass, ...traitLibraries) => {
for ( const traitLibrary of traitLibraries ) {
const traits = require(paths.modules + "/traits/" + traitLibrary);
for (const [trait, implementation] of Object.entries(traits)) {
if (klass.prototype[trait]) {
throw new Error('FATAL: Trait method ' + trait + ' already defined in the class.');
}
klass.prototype[trait] = implementation;
}
}
return klass;
}
*Thread Reply:* It's a limited implementation of the Ruby notion of traits using the JavaScript prototypical inheritance.
*Thread Reply:* You would pass your World class as the first argument, and the rest of the function can be overloaded with library names. Here's a call to the function from my code: const Page = loader.applyTraits(loader.getClass("Page"), "Actions", "FormMethods", "WaitMethods", "UcxFields");
*Thread Reply:* Each trait library is simply an object of callbacks.
*Thread Reply:* Hmm.. Reading closer you're moving in the same direction as what I posted. What you have should work if the body of foo.js is this:
module.exports = function() {
//do stuff
}
HOWEVER!!!
This will NOT work
module.exports = () => {
// do stufff
}
Arrow functions do not have a bindable scope, and bind does nothing to them. You can attach one to the world object, but it won't have access to this
*Thread Reply:* The method I posted above is looking for the trait libs to look like this:
module.exports = {
foo: async function () {},
moo: function () {},
bar: function (arg1, arg2) {}
}
And so on.
I've ran into a problem with Cucumber's current handling of multiple arguments, and I'm not sure there is a solution to it. I have these two step defs:
defineStep(/I log in as an? (administrator|manager|read-only user)/, iFleetLogin);
defineStep(/I log into an? (\w+) account as an? (administrator|manager|read-only user)/, loginCallback);
The loginCallback is an async function. It needs to have an optional argument - and that's a major catch and monkey wrench
*Thread Reply:* This workaround works, but it's pesky
defineStep(/I log in as an? (administrator|manager|read-only user)/, async function(permission) {
await login.bind(this)(permission);
});
*Thread Reply:* ? after a capture or group means 0 or 1 of the preceding one. The same way as an? means the same as a(?:n)?
it could be a failure in hooks as well as your scenario. I don't know without checking.
Hi, are there anyone in here encountered stale element reference: element is not attached to the page document , I've been looking for a solution lately but got no luck.
as the name suggests, that is a browser automation failure caused by a stale element ref.
an element reference changes when one of many things occur. Usually one of 3 things
Itself is mutated after being located It's parent or containing parents/frames are mutated after being located It has had a style change or cosmetic change which causes the element to be reloaded
Hello, i've just discovered the rule (https://cucumber.io/docs/gherkin/reference/#rule) keyword, the documentation seems to imply that it can be used in conjunction with the example keyword as a synonym for Scenario.
When I try this locally and here https://cucumber.github.io/cucumber-js/ it doesn't seem to execute.
Would this example be incorrect:
Feature: Simple maths
Rule: My first rule
Example: easy maths
Given a variable set to 1
When I increment the variable by 1
Then the variable should contain 2
I saw that it says this is Gherkin 6, I can't find where cumberjs states the version of gherkin that it supports.
*Thread Reply:* What version of cucumber-js itself are you running locally?
*Thread Reply:* Okay - Rule is supported from 7.0.0 onlyhttps://www.npmjs.com/package/@cucumber/cucumber
*Thread Reply:* Right, thanks @David Goss looks like its still prerelease too: > 7.x.x and above > (Not yet released)
*Thread Reply:* Don't worry, there is a stable 7.0.0 out! Maybe a small hiccup in the release process there with that readme.
*Thread Reply:* I'll upgrade and see how I go, I think i'll need a new html reporter too
*Thread Reply:* @Des Horsley cucumber-js 7 has a new HTML formatter built-in
Hello, is there a decently comprehensive / real life project that uses cucumber (javascript)? That is also open sourced? I wanted to see an example of a comprehensive application of cucumber.
Hi Community, ( using Cucumber JS ) I would need your help/expertise in finding the solution to my problem , " I want to pass the multiple test data in Examples ( with Json File Name as a normal String ) and i should be writing a code to read the Files and use the different set of test data for one function (e:g function login() -------------->>>>> Example of my test Scenario Outline: Sign in successful with post idm user - <service> * Given I am a user with *<service> * When I sign in with *valid credentials And I close the tutorial screen Then I am taken to the dashboard view Examples: |service| |a single prepay connection| |a single Postpay connection|
*Thread Reply:* @Chats I'm not sure I understand what you're asking for.
*Thread Reply:* Do you want to load test data from an external file?
*Thread Reply:* @Aslak Hellesøy Yes my external file (.json) in some folder and i wanna pass the file name as a string in examples ( jsut for readable purpose ) and i wanna write a logic where i can read the file by matching the string passed in examples of scenario and get the values of json
*Thread Reply:* @Aslak Hellesøy I have a class written in Java which is a UserProfileReader class but i am struggling to implement it in Js
Hi everyone! In ruby there’s an AfterConfiguration hook that gives us the instance of Cucumber Configuration that contains information like the formatters specified and tags used for the test run. Is there an equivalent way to access that information from a hook in Cucumber JS?
*Thread Reply:* Hi @MarkSweetlove - I'm afraid there isn't. What do you need it for?
*Thread Reply:* In ruby it allowed us to add a custom formatter at runtime to avoid specifying it on the command line every time.
*Thread Reply:* @MarkSweetlove you can define common command-line options in a cucumber.js config file in your project root: https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#profiles
*Thread Reply:* Here is cucumber-js' own config: https://github.com/cucumber/cucumber-js/blob/master/cucumber.js
*Thread Reply:* On Ruby we could update the cucumber config from our own third party gem by registering the hooks which was ideal for our scenario, but doesn’t sound like that’s an approach we can take in JS.
I have, but I am one of the maintainers, so maybe that doesn't count 🙂
OMG - great. so I was like on cucumber 5.1.0 and upgraded to 7.0.0
❯ more ./node_modules/@cucumber/cucumber/bin/cucumber-js
#!/usr/bin/env node
require('../lib/cli/run.js').default();
@Huck Carignan have you followed the upgrade instructions? https://github.com/cucumber/cucumber-js/blob/master/docs/migration.md
I did, but I'll run through them another time incase I missed a step
I noticed that the node_modules/.bin/cucumber-js contains : require('../lib/cli/run.js').default();
I have the same as you in node_modules/.bin/cucumber-js :
```#!/usr/bin/env node
require('../lib/cli/run.js').default();``` What do you think is incorrect about it?
If you're still getting Cannot find module 'cucumber' then that's likely from some other code you have lying around that still tries to load the old cucumber module. Perhaps the stack trace will point you to what file that is?
Does the stack trace not tell you what file is trying to load cucumber
you were right - I found a hidden old cucumber reference - after that was removed, it ran
Bonjour! "Guys" is easily replaced with the more gender-neutral "Folks" or "All". We'd appreciate if you tried to use that. Thanks!
*Thread Reply:* I got it running, but I'm now having issues with the @tags. I believe it might be an issue with the formatter changes. I won't be able to investigate this for another few hours (other work priorities)
Hi @Aslak Hellesøy - I am trying to implement where i can pass just name of the json file without .json extension in examples and read this file by writing the logic behind it, is this achievable , or whats the best practice to pass multiple test data to one scenario through Json ?
*Thread Reply:* @Chats Just read the file in your step definition
*Thread Reply:* @Aslak Hellesøy i want to have it dynamic , as json passed in examples of scenario will be the name ( |some file1| and few more files as well |some file 2| and these files are under some UserProfile folder ( somefile1.json,------> now i wanna write a code in js which which will pick that json file from UserProfile folder by replacing some file1 to somefile1.json and read the file and return the values which eventually i want to use it in functions.
*Thread Reply:* @Chats Can you write your step definition so it receives the base name of the JSON file as an argument?
*Thread Reply:* When you have done that, just use fs.readFile to read the contents of the JSON file.
*Thread Reply:* @Aslak Hellesøy, Thanks , I will try to implement this solution
Hi all, perhaps a bit of a weird scenario and there’s every possibility it’s something I’m doing that’s wrong, but I have built a lightweight Slack app that allows my team to execute our Cucumber tests remotely. This all worked fine in cucumber-js 6.x, but I get a strange error in 7.0.0.
I kick off the Cucumber run with:
cucumber.Cli({
argv: process.argv,
cwd: process.cwd(),
stdout: process.stdout,
}).run()
And the first test run succeeds on 7.0.0. The second run however fails instantly with this:
```/node_modules/@cucumber/cucumber/lib/runtime/parallel/coordinator.js:56 this.supportCodeIdMap[id] = this.supportCodeLibrary.stepDefinitions[index].id; ^
TypeError: Cannot read property 'id' of undefined at /nodemodules/@cucumber/cucumber/lib/runtime/parallel/coordinator.js:56:88 at arrayEach (/nodemodules/@cucumber/cucumber/nodemodules/lodash/lodash.js:530:11) at Function.forEach (/nodemodules/@cucumber/cucumber/nodemodules/lodash/lodash.js:9410:14) at Coordinator.saveDefinitionIdMapping (/nodemodules/@cucumber/cucumber/lib/runtime/parallel/coordinator.js:55:26) at Coordinator.parseWorkerMessage (/nodemodules/@cucumber/cucumber/lib/runtime/parallel/coordinator.js:35:18) at ChildProcess.<anonymous> (/nodemodules/@cucumber/cucumber/lib/runtime/parallel/coordinator.js:88:18) at ChildProcess.emit (events.js:315:20) at emit (internal/childprocess.js:903:12) at processTicksAndRejections (internal/process/taskqueues.js:81:21) { CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {} ], CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {} ] } % events.js:292 throw er; // Unhandled 'error' event ^
Error [ERRIPCCHANNELCLOSED]: Channel closed at process.target.send (internal/childprocess.js:705:16) Emitted 'error' event on process instance at: at internal/childprocess.js:709:35 at processTicksAndRejections (internal/process/taskqueues.js:75:11) { code: 'ERRIPCCHANNEL_CLOSED', } events.js:292 throw er; // Unhandled 'error' event ^
Error: write EPIPE at process.target.send (internal/childprocess.js:832:20) at process.target.send (internal/childprocess.js:703:19) Emitted 'error' event on process instance at: at internal/childprocess.js:836:39 at processTicksAndRejections (internal/process/task_queues.js:75:11) { errno: -32, code: 'EPIPE', syscall: 'write', CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {} ], } events.js:292 throw er; // Unhandled 'error' event ^
Error: write EPIPE at process.target.send (internal/childprocess.js:832:20) at process.target.send (internal/childprocess.js:703:19) Emitted 'error' event on process instance at: at internal/childprocess.js:836:39 at processTicksAndRejections (internal/process/task_queues.js:75:11) { errno: -32, code: 'EPIPE', syscall: 'write', CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {} ], } events.js:292 throw er; // Unhandled 'error' event ^
Error: write EPIPE at process.target.send (internal/childprocess.js:832:20) at process.target.send (internal/childprocess.js:703:19) Emitted 'error' event on process instance at: at internal/childprocess.js:836:39 at processTicksAndRejections (internal/process/task_queues.js:75:11) { errno: -32, code: 'EPIPE', syscall: 'write', CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {}, CallSite {} ], }``` I’m completely lost to be honest, as I say this all worked fine with identical code on 6.x. Any ideas?
*Thread Reply:* So the error code is very declarative. It's telling you your fetch is failing on the index. So before you do anything else. Debug the line before execution and return the 1d-array in both versions. Triage from there.
*Thread Reply:* Looks like index is out of bounds, or the array has undefined values (less likely). Something might be wrong in coordinator.ts. BTW we need source maps to get better stack traces. Any idea @charlierudolph @David Goss ?
*Thread Reply:* Here's the line of code https://github.com/cucumber/cucumber-js/blob/master/src/runtime/parallel/coordinator.ts#L108
*Thread Reply:* Seems to suggest the coordinator and worker don't have the same information about the step definitions somehow.
*Thread Reply:* @Jim Trenowden would you be able to share something that would help us reproduce this?
*Thread Reply:* I'm not super familiar with this area so first step is to reproduce. @Jim Trenowden would it be practical for you to post your project to github (or an edited versin of it)?
*Thread Reply:* @Aslak Hellesøy we do ship source maps in the package, but not the actual TypeScript source files, which explains that. I'll do a PR for that soon.
*Thread Reply:* Thanks for looking into this! It’s a huge project at my workplace so not really practical to share it (not my IP strictly speaking, even though I wrote it), but the file calling the Cucumber CLI looks like this if that’s helpful?
```const cucumber = require('@cucumber/cucumber')
async function cucumberRunner(tags, scenarioPath, parallel, jsonPath) {
const argv = process.argv
const cucumberArgs = argv.concat(
'--parallel',
parallel,
'--tags',
tags,
'--format',
json:${jsonPath},
scenarioPath
)
return await new cucumber.Cli({ argv: cucumberArgs, cwd: process.cwd(), stdout: process.stdout, }).run() }
module.exports = { cucumberRunner }```
*Thread Reply:* Thanks @Jim Trenowden I must admit I'm not at all familiar with the parallel implementation. But I know enough about parallelism that it's difficult to implement without concurrency bugs!
*Thread Reply:* i’ve noticed that if I knock the parallel threads down to 1 the first run of tests still passes fine, but in the second one the steps are undefined
It’s worth noting that the app that calls the above file is a Node.JS app that stays alive inbetween test runs if that makes a difference
*Thread Reply:* Hmm. Perhaps we have some sticky state somewhere that prevents Cucumber from running properly more than once in the same Node process?
*Thread Reply:* Possibly related: https://github.com/cucumber/cucumber-js/issues/1278#issuecomment-580603152
*Thread Reply:* Source maps fix is here https://github.com/cucumber/cucumber-js/pull/1607
*Thread Reply:* Ah interesting, yeah issue 1278 does sound similar to what I’m seeing. Glad it’s not just me then!
*Thread Reply:* Although it’s weird that this only started happening in v7, in v6 this all works absolutely fine
*Thread Reply:* So clearing the Cucumber module cache between runs seems to “resolve” this, seems a bit hacky but it’s unblocked me at least. Thanks!
Is there any way to start cucumber from another js file? Cause my package.json is getting nightmarish
"test-allstar": "./node_modules/.bin/cucumber-js ./tests/features ./tests/themes/allstar/features --require ./tests/init.js --require ./tests/steps --require ./tests/themes/allstar/steps --publish-quiet",
"test-allstar-v2": "./node_modules/.bin/cucumber-js ./tests/features ./tests/themes/allstar-v2/features --require ./tests/init.js --require ./tests/steps --require ./tests/themes/allstar-v2/steps --publish-quiet",
"test-ifleet": "./node_modules/.bin/cucumber-js ./tests/features ./tests/themes/ifleet/features --require ./tests/init.js --require ./tests/steps --require ./tests/themes/ifleet/steps --publish-quiet",
"test-sme": "./node_modules/.bin/cucumber-js ./tests/features ./tests/themes/sme/features --require ./tests/init.js --require ./tests/steps --require ./tests/themes/sme/steps --publish-quiet",
*Thread Reply:* The exact feature sets to be tested depend on the brand theme in use, and the step definitions change as well based on this.
*Thread Reply:* npm adds ./node_modules/.bin/ to the PATH so no need to add that.
You can also execute arbitrary commands from npm scripts so just extract to a shell script
*Thread Reply:* That's not what I'm asking. Look at the god-awful argument list being passed to cucumber - that's what I'm asking about please - how to get rid of that.
*Thread Reply:* I also recommend adding common cucumber options in cucumber.js - see https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#profiles
*Thread Reply:* Here is cucumber-js' own config: https://github.com/cucumber/cucumber-js/blob/master/cucumber.js
*Thread Reply:* But I still need to start a hugo webserver and an express.js server, preferably before Cucumber does anything.
*Thread Reply:* No, my preference is really to do it in a Before hook. That way I have less of a chance having server state accidentally leaking between scenarios
*Thread Reply:* That would add 2 minutes to all scenarios and cause the tests to run for 4 hours. So, no.
*Thread Reply:* Besides, in my case that's an unwarranted concern. I'm testing static javascript files built by Hugo, not a webserver that carries any sort of state.
*Thread Reply:* Yeah, if you have no state I agree BeforeAll is better.
*Thread Reply:* I do use a Before hook to force a reset of the Express server though.
*Thread Reply:* But that thing comes up in microseconds as opposed to a full minute or two.
*Thread Reply:* Yeah, this will help a lot. I'm reading the profile information now.
*Thread Reply:* Even though it wasn't the question I asked, I didn't realize ./node_modules/.bin was on path so that does help.
*Thread Reply:* Thank you for your time and I'm sorry if I came across as snippy - I've been dealing with a really weird and frustrating bug this morning.
Played around with profiles this morning. Seems sorta useless because I can't declare different feature sets with it - just different command line flags. What am I missing?
How many different feature sets do you want to define @Michael Morris? I've always used tags to differentiate between sets, and I have never found the need to enumerate what feature files to execute.
Why do you need this?
*Thread Reply:* I have a core application, and currently three brands. The brands have their own features, and the core specifications have different step definitions. I could use tagging as you describe and keep the features in one folder, but I'd have to write skip logic to skip tests belonging to brands other than the current one.
*Thread Reply:* I've built a test runner that starts cucumber off as a child process. It also goes ahead and starts the Hugo Web Server and Express.js Mock server, and stops them when the Cucumber process fires its exit event. The approach will work, though I wish I had an easy way to relay command line flags to Cucumber.
*Thread Reply:* @Michael Morris I dunno if this will help in your context, but I worked on a set of feature files the BBC had to specify a TV app that was run on lots of different TV’s “browsers” and a Flash-based set-top-box. We used the same set of feature files to test each TV, but tagged out scenarios that were not supported / applicable on some platforms. e.g. @not-samsung-tn482
You might find it’s more manageable to have all the specifications in one place and just tag out the discrepancies.
*Thread Reply:* I'm facing something very similar actually. One of the reasons that I'm wanting to keep the features in two directories is we are considering putting the brand themes off into their own repository modules. That would require their features stay with the rest of the code.
*Thread Reply:* I was tagging them earlier though and I didn't remove the code supporting it - @theme=ifleetfor example.
Question: I used to run features with @tags, i.e.-
In the feature file, I have:
@New
Feature: 300 Manual Workflow with Group Approval turn off
In my package.json, I have:
"scripts": {
"test": ".node ./node_modules/.bin/cucumber-js --tags @New"
*Thread Reply:* Tags should be working as before. Can you elaborate on what you’re seeing?
*Thread Reply:* yea, I was just about to edit my above question so that is clearer. 🙂
*Thread Reply:* That was working fine on the original cucumber-js module
*Thread Reply:* Weird question, but are you using any particular formatters? I've noticed issues with tags and the progress-bar formatter in v7
*Thread Reply:* So I've had to stop using the progress-bar formatter as I've noticed that it will sometimes ignore the tags provided and run all scenarios in the feature path
*Thread Reply:* Whereas not using that formatter seems to make everything behave as expected in v7
*Thread Reply:* Haven't tested other formatters to see if they have the same issue
*Thread Reply:* sounds like we're referring to https://github.com/cucumber/cucumber-js/issues/1579
*Thread Reply:* which is a bug where the progress bar formatter incorrectly reports the total number of steps (not accounting for the tag filter)
*Thread Reply:* but the formatter can't influence what's run or not run
*Thread Reply:* Ah-ha! Yes, knew I wouldn't be the first to spot this. Good to know it's been raised
*Thread Reply:* so i think it's likely that your tag expression is working (only the scenarios you wanted are run) but it just doesn't look that way from the output
*Thread Reply:* Run it with or without - the progress bar is just misreporting
*Thread Reply:* I'm trying now without the progress bar to see what happens
*Thread Reply:* Yup, I believe you gentlemen are correct. Just a bug with the progress bar - not the test cases being run
It would be nice if steps BeforeAll and AfterAll could see the worldParameters. I can work around the fact that they can't, but it's annoying.
*Thread Reply:* Specifically, I need both of them to see the browser configuration that I pass in as world params. When I have the headless mode of puppeteer turned off I want to leave the browser running when the test concludes. This allows the developer to interact with it after the test to work on things.
*Thread Reply:* My current work around is to put Before, BeforeAll and AfterAll in the same file. The browserConfig is a variable all these closures can see. Before inits the browser once only since BeforeAll can't without the config. AfterAll then looks at that var to determine if it's turning off the browser.
*Thread Reply:* This may happen soon-ish, see https://github.com/cucumber/cucumber-js/issues/1393
But also, would generally recommend an instance of puppeteer per test (world) rather than sharing one across the whole test run. Ensures segregation between tests and allows for running in parallel.
*Thread Reply:* As mentioned, there are things that would be nice to share in the world in beforeall /afterall. But each beforeall / afterall currently spins up a new world instance so it's a bit intractable>
Also as David said, definitely don't share browser state. Should tear up / tear down the browser
Is there a resource about how to convert from cucmberjs to @cucumber/cucumberjs? I’m getting Cannot set property 'World' of undefined now that I’ve updated.
~I actually would prefer to not switch, but elements aren’t getting clicked, even though they are getting found and they are scrolled into view.~ I’ve gone crazy. This is a puppeteer problem, not a cucumber problem.
For reference anyway, there's a migration guide here https://github.com/cucumber/cucumber-js/blob/master/docs/migration.md - feedback welcome
Is there any way to retrieve the number of tests that are about to be executed in either the beforeAll hook or the testRunStarted event in a formatter? I’d love to be able to report the percentage of the test run that is complete after a scenario but i can’t find the information… I can get all the features/scenarios in the project from the gherkinDocument but not which ones are actually going to be executed based on the path or tag selection specified by the user.
*Thread Reply:* I’m afraid I’m not familiar enough with the code these days to know. @David Goss should know.
*Thread Reply:* Hey @MarkSweetlove, we do have a bit of a gap here. There is a testCase message which is effectively what you want - only emitted for a compiled scenario that is going to actually run - but at the moment the testCase message is emitted just before that test case executes. To have an accurate progress indicator we need to emit them all upfront before any tests execute - I'm actually working on this now under https://github.com/cucumber/cucumber-js/issues/1408, because I need it to solve https://github.com/cucumber/cucumber-js/issues/1579 at which point the progress bar formatter should serve as a good reference point for your use case. Please go ahead and watch those issues and hopefully this will be resolved pretty soon.
*Thread Reply:* Thanks David. Appreciate your response and I’ll watch those issues excitedly!
How do I pass command line arguments to cucumber? Like there is this concept of world parameters, but since the world is per test, I can't do anything with those parameters in a before all or after all.
*Thread Reply:* We’re going to make world parameters available to BeforeAll and AfterAll hooks soon, see https://github.com/cucumber/cucumber-js/issues/1393
Is anyone using lint tool for Gherkin scripts in the feature file? I am setup a new project and would like to add it so everyone in the team can follow the same rules. Currently I am looking at https://github.com/vsiakka/gherkin-lint which I think is what I can find the most popular one?
*Thread Reply:* There's also https://github.com/darrinholst/eslint-plugin-cucumber for linting your step code, if that might be useful to you.
Is anyone else experience Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/formatter/helpers' is not defined by "exports" in /Users/me/dev/cucumber-playwright/node_modules/@cucumber/cucumber/package.json with the new 7.2.0?
*Thread Reply:* It seems to be related to the following issue: https://github.com/cucumber/cucumber-js/issues/1646
*Thread Reply:* yep - think we'll need to revert and then publish a 7.2.1 so we can regroup - i'll do that today
*Thread Reply:* @Tally Barak 7.2.1 is out which should unblock you - sorry about that!
*Thread Reply:* This looks like a warning from eslint. Does the code execute as expected @Deb Learns?
*Thread Reply:* Good, not sure how to get rid of that warning though.
*Thread Reply:* Yeah the linter has no way of knowing that cucumber-js is going to bind the world to that function internally - a bit of a non-deterministic rule on that basis really. You could consider disabling that rule for your step_definitions specifically.
*Thread Reply:* If you feel like using TypeScript for your step definitions, you can then tell the compiler what this will be, see https://www.typescriptlang.org/docs/handbook/functions.html#this-parameters
Does any one know anything for rerun/retry a failed Scenario ? The reason is I have some Scenarios reply on unstable integration. If a server return 500 error temporally which failed the scenario, I want to rerun the Scenario automatically.
I only see a formatter called rerun , it then need another cucumber run to rerun which I feel a little different with what I am expecting.
*Thread Reply:* Hello 🙂
Here's the .feature file for the rerun formatter:
https://github.com/cucumber/cucumber-js/blob/1109951440833c7f074b04d1b294e96ff1be65eb/features/rerun_formatter.feature
The idea is to use that formatter to output failures in a specific file which will then be used as an argument to a second execution of cucumber.
*Thread Reply:* Thanks @Aurélien Reeves! I was thinking another way to retry automatically multiple times without reporting. But maybe report it and run it failed one again is better approach. 🤔
*Thread Reply:* @Tim Yao https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#retry-failing-tests
*Thread Reply:* @Aslak Hellesøy That’s what exactly I am looking for! Thanks! Will try it Monday.
The cucumber data tables print with all the columns lined up. How do I make sure the columns don’t try to line up? I’ve got some column values that are very long and it makes the already long table much longer.
*Thread Reply:* @plocket there is no way to do this currently. I suggest you use column values with a custom toString() method. Or, you could open an issue where we could discuss adding a feature that lets you control table formatting.
*Thread Reply:* I’m not sure how/where I’d use a custom toString() method on column values, but I do know how to make an issue. Thank you.
*Thread Reply:* I forgot that in JavaScript you cannot control the type of table cells (you can in Java). See you in the ticket.
Hi folks, not sure if this is a bug or I'm doing something wrong. I'm trying to migrate from v6 to v7, and I can't quite get my custom formatter to work again. After following some v7 formatter examples, I have code like this: ```import { Formatter, formatterHelpers } from "@cucumber/cucumber" import { IFormatterOptions } from "@cucumber/cucumber/lib/formatter" import { messages } from "@cucumber/messages" import IEnvelope = messages.IEnvelope
export default class CustomFormatter extends Formatter {
constructor(options: IFormatterOptions) {
super(options)
options.eventBroadcaster.on("envelope", (envelope: IEnvelope) => {
if (envelope.testStepStarted != null) {
if (envelope.testStepStarted.testCaseStartedId == null) { return }
try {
const testCaseAttempt = options.eventDataCollector.getTestCaseAttempt(envelope.testStepStarted.testCaseStartedId)
const parsed = formatterHelpers.parseTestCaseAttempt({
cwd: this.cwd,
snippetBuilder: this.snippetBuilder,
supportCodeLibrary: this.supportCodeLibrary,
testCaseAttempt,
})
<a href="http://console.info">console.info</a>(parsed)
} catch (error) {
console.error(error.message)
}
}
...```
And for every step, it throws on const parsed = formatterhelpers.parseTestCaseAttempt({ ...
"Cannot read property 'status' of undefined"
"TypeError: Cannot read property 'status' of undefined
at parseStep (/Users/me/Git/MyProject/node_modules/@cucumber/cucumber/lib/formatter/helpers/test_case_attempt_parser.js:55:24)
at /Users/me/Git/MyProject/node_modules/@cucumber/cucumber/lib/formatter/helpers/test_case_attempt_parser.js:93:28
at arrayEach (/Users/me/Git/MyProject/node_modules/@cucumber/cucumber/node_modules/lodash/lodash.js:530:11)
at Function.forEach (/Users/me/Git/MyProject/node_modules/@cucumber/cucumber/node_modules/lodash/lodash.js:9410:14)
at Object.parseTestCaseAttempt (/Users/me/Git/MyProject/node_modules/@cucumber/cucumber/lib/formatter/helpers/test_case_attempt_parser.js:80:22)
at EventEmitter.<anonymous> (/Users/me/Git/MyProject/packages/server/build/E2eTest/formatters/CustomFormatter.js:23:64)
at EventEmitter.emit (events.js:327:22)
at EventEmitter.emit (domain.js:486:12)
at PickleRunner.aroundTestStep (/Users/me/Git/MyProject/node_modules/@cucumber/cucumber/lib/runtime/pickle_runner.js:165:31)
at PickleRunner.run (/Users/me/Git/MyProject/node_modules/@cucumber/cucumber/lib/runtime/pickle_runner.js:206:28)
at Runtime.runPickle (/Users/me/Git/MyProject/node_modules/@cucumber/cucumber/lib/runtime/index.js:83:43)
at tryCatcher (/Users/me/Git/MyProject/node_modules/bluebird/js/release/util.js:16:23)
at Object.gotValue (/Users/me/Git/MyProject/node_modules/bluebird/js/release/reduce.js:166:18)
at Object.gotAccum (/Users/me/Git/MyProject/node_modules/bluebird/js/release/reduce.js:155:25)
at Object.tryCatcher (/Users/me/Git/MyProject/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/me/Git/MyProject/node_modules/bluebird/js/release/promise.js:547:31)"
*Thread Reply:* Also strange, is that the same basic logic works perfectly fine when the scenario ends:
if (envelope.testCaseFinished != null) {
if (envelope.testCaseFinished.testCaseStartedId == null) { return }
const testCaseAttempt = this.eventDataCollector.getTestCaseAttempt(envelope.testCaseFinished.testCaseStartedId)
const parsed = formatterHelpers.parseTestCaseAttempt({
cwd: this.cwd,
snippetBuilder: this.snippetBuilder,
supportCodeLibrary: this.supportCodeLibrary,
testCaseAttempt,
})
<a href="http://console.info">console.info</a>(parsed)
}
this is not throwing any errors
*Thread Reply:* I don't know the code, but I've had a look. It seems like the error you're getting is probably thrown from here:
https://github.com/cucumber/cucumber-js/blob/v7.2.1/src/formatter/helpers/test_case_attempt_parser.ts#L116 (I guess the line numbers are different in the typescript source?)
If that's true, this suggests the testStepResult is undefined in that function.
That function's called here: https://github.com/cucumber/cucumber-js/blob/v7.2.1/src/formatter/helpers/test_case_attempt_parser.ts#L169
and the line above it that sets the testStepResult is here:
https://github.com/cucumber/cucumber-js/blob/v7.2.1/src/formatter/helpers/test_case_attempt_parser.ts#L157
So it seems like the code is assuming that every one of the testSteps will have a corresponding entry in the stepResults map, and that this isn't the case here?
It seems like this is a bug; I wonder if you could add some debugging into the cucumber source code on your machine to see if we can pinpoint what's wrong?
Hi all, is there a way to attach custom metadata to Cucumber messages (with the aim to add them to the HTML report)? Using cucumber-js 7.2.1
*Thread Reply:* Anything you attach from a step will come up in the report (long as it's in some displayable form). Are you able to say more about what you want to show and how?
*Thread Reply:* Sure, so previously I was using the cucumber-html-reporter package for our reports, and that allowed us to attach custom metadata to the “top” of the report that related to the whole test run, rather than a specific step or scenario.
Some of the metadata we were adding is at the top of the new HTML reports already, such as duration, OS, Node JS version etc. But we were also attaching things such as the feature path and tag combination that was used to kick off the test run, test environment, browser (as we’re using Cucumber to kick off Selenium tests) etc.
The data at the top of the new HTML reports seems to be coming from the meta object in the message formatter, if there was an easy way to inject custom metadata in there that would be great
*Thread Reply:* Can you give an example (in JSON) of what you'd like to attach, and how you'd like it to be displayed?
I'm developing an application to check a number of different websites using Selenium. I'd like to specify the "up" or "down" criteria for each website as a Cucumber Scenario (one scenario per site). The application is going to run periodically and write its results to a database, and will be hosted in AWS Lambda.
What I want to know is how do I write the code that processes the individual steps of each Scenario? In other words:
• where do I define the functions that process the individual steps, e.g. Given, When, etc.?
• How do I pass the statements comprising each Scenario to those functions?
• How do I get the result of processing each Scenario?
In more concrete terms, given this function definition:
function handler() {
const sites = getSitesToTest(); # array of strings
for (const site of sites) {
const statements = getStatements(site); # array of strings
ok = processStatements(statements); # returns Boolean
writeToDatabase(site, ok)
}
}
How do I define processStatements()?
The docs seem fairly clear on how to write the individual Given(...), When(...), functions. It's tying those functions (and Cucumber in general) into my application that I'm having trouble with.
EDIT: See my previous message for the context this message should be read in.
*Thread Reply:* Hello @Kit Peters 🙂
Here's a simple example of an app and its cucumber tests: https://github.com/cucumber-ltd/shouty.js
As you can see in https://github.com/cucumber-ltd/shouty.js/blob/master/features/step_definitions/shout_steps.js, it requires the code from your app, and uses the function as you would do with any module
Will that help?
*Thread Reply:* @Aurélien Reeves I'm sorry, I wasn't clear. The message at the root of this thread follows on from the message before it. I don't need to know how to write a standard test using Cucumber; there are numerous good examples (such as yours) of that. What I need to know is how, at a functional level, to process a user-defined scenario using Cucumber and get the result of that processing in a variable that I can then write to a database.
*Thread Reply:* I'm not sure I understand. Let me state it another way. I want a function that takes a scenario in the form of an array of strings and returns a boolean indicating whether or not the scenario was successful.
*Thread Reply:* I'm trying to use Cucumber in an application context, not a test context.
*Thread Reply:* Why would you need the scenario in the form of an array of strings ?
Beside that, I would say that what you are looking for is a custom formatter. You can take a look here to take a look on how to build your own formatter : https://github.com/cucumber/cucumber-js/blob/main/docs/custom_formatters.md
*Thread Reply:* I need the scenario in the form of an array of strings because the scenario will be supplied by the user. I will not be defining the scenario beforehand.
*Thread Reply:* And the custom formatter doesn't help me get my scenarios into Cucumber in the first place.
*Thread Reply:* I have an idea that might help explain what I'm trying to do.
*Thread Reply:* Suppose I were to write a command line application that would allow the user to input their own scenarios via the keyboard. How would I send the user input to Cucumber?
*Thread Reply:* Ok, I understand now 😛
Right now I do not have the time to go into much details. I will look deeper tomorrow.
I think what need to be done is: • generate a feature from those string arrays • parse it with gherkin: https://github.com/cucumber/common/tree/master/gherkin/javascript • run the resulting pickels with the cucumber-js runner: https://github.com/cucumber/cucumber-js/tree/main/src/runtime • then use a dedicated formatter for the post process of the results It is actually not trivial, I am not sure we have an API that would make that process easier, but I still do not know that much the API 😛
Maybe @David Goss or @charlierudolph would have better ideas?
*Thread Reply:* I've been speaking with @David Goss in another thread, but he hasn't responded to my last message. I haven't spoken with @charlierudolph.
*Thread Reply:* Those steps look very close to what I'm trying to accomplish.
We have a service that will analyze the json output (using the cucumber-json-formatter tool) and have noticed that when we upgraded to use the cucumber-7 version the format of the URI of a feature in the ndjson file now has a prefix of the current directory. Is there a way to turn this off and revert back to not include that value?
Previously we were seeing something like:
"uri":"features/Compare/AddProviderToCompare.feature","id":"add_providers_to_compare","keyword":"Feature" and now we are seeing "uri":"/cucumber/features/Compare/AddProviderToCompare.feature","id":"add_providers_to_compare","keyword":"Feature" notice the addition of the prefix of /cucumber/ to the uri.
We are NOT seeing this same format using cucumber ruby and would like to be able to have consistency between the two outputs.
Again, does anyone know of a way to turn off this additional content to the uri for features?
*Thread Reply:* To clarify, a bug in the cucumber js logic in writing out the messages to cucumber.ndjson?
*Thread Reply:* Yes, as I understand it we have duplicated formatters in each of the cucumbers that write out this JSON format.
It's a long weekend in Europe, so might be best to raise an issue on cucumber-js so this doesn't fall through the net.
*Thread Reply:* I think this is https://github.com/cucumber/cucumber-js/issues/1534
*Thread Reply:* Last change to fix this will land next week (depends on https://github.com/cucumber/cucumber-js/pull/1645 but nearly there)
*Thread Reply:* Yes, that sounds like the issue, thank you. I will check back in after that lands.
*Thread Reply:* @David Goss, when do you think this fix will be released?
Does cypress-cucumber-preprocessor works with plugin/index.ts typescript file?
my feature file is not recognised if I am writing preprocessor code in plugin/index.ts
*Thread Reply:* That plugin is not supported by us. I suggest you ask the authors of the plugin @SantoshK
Any one know the best way to handle error in BeforeAll hook?
Is below the right way? Or there is a better way?
BeforeAll(async () => {
if (//something wrong) {
throw new Error('Something is wrong');
}
}
*Thread Reply:* If a hook fails to do what it needs to do, it’s best to throw an error as you have suggested.
I'm looking for a decent updated javascript walkthrough. I found one from 2018 that has not been updated since.
*Thread Reply:* @Michael Stelly this one is pretty good: https://turriate.com/articles/modern-javascript-everything-you-missed-over-10-years
*Thread Reply:* @Michael Stelly the change log is probably the best place to look.
https://github.com/cucumber/cucumber-js/blob/main/CHANGELOG.md
*Thread Reply:* Let me rephrase: I'm looking for a current guided walkthrough to help me understand the workflow for cucumber similar to this 3-year old blog post http://www.thinkcode.se/blog/2018/02/07/getting-started-with-cucumber-for-javascript.
*Thread Reply:* I found the example file in the repo. That should help to get me started.
Hi Folks, I need some help, how to run multiple examples in the scenario outline without login all the time for each example, so in short, i want to login once and want to test all the multiple examples in my scenario, is it possible to run each row once without repeating all the steps again for all the rows ?
*Thread Reply:* Yes, it's possible.
Cucumber scenarios (whether they come from regular scenarios or examples in a scenario outline table) are intended to be independent, to avoid the
Given this, here are your options:
*Thread Reply:* So we have this situation. And I would advocate a fourth option - But it's not test architecture, it's software architecture. (Matt also would probably push for this irl).
If the logging in isn't something you care about testing, and it's something which is causing a pain point in terms of test execution and it's either not directly your system, or a system you are confident in it's existing functionality, then adding a bypass or backend is advised.
*Thread Reply:* at CA we have to login using a different website currently then redirect and pass a cookie, so we just artificially generate this. It removes 99% of the logging in time.
Bonjour! "Guys" is easily replaced with the more gender-neutral "Folks" or "All". We'd appreciate if you tried to use that. Thanks!
Where would I find the cucumber.js file described here?
To disable this message, add this to your ./cucumber.js:
│ module.exports = { default: '--publish-quiet' }
You just create it in your project's root directory. Documented here: https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md#profiles
*Thread Reply:* ahh Thank you. I didn't know it was a custom config file. I assumed it was something already created.
*Thread Reply:* I appreciate the help during my learning curve. I'll be sure to pay it forward.
Ah ha! I found the Cucumber School tutorials. They didn't exist my last go round. For the record, anyone landing here with questions such as those I had, all those answers are found in the first few modules of that free training. Well done, folks!
*Thread Reply:* Great, glad you're liking them. Please post any feedback directly to the team in <#CCK3ZFSF9|school-devs> - we're still working on the last few episodes.
So, don your thinking caps, grab a pickle, get some schoolin'! Cucumber School 🎓
Has anyone used the new(ish) @cucumber/gherkin-streams package? I've been having some trouble requiring it: https://github.com/cucumber/cucumber-js/issues/1675
*Thread Reply:* Crosspost:
If you try something like the following, does it work? ```const { GherkinStreams } = require('@cucumber/gherkin-streams')
const stream = GherkinStreams.fromPaths(/.../)``` If so, it seems to be an error in the documentation
Does anyone have any insight into this comment (https://github.com/cucumber/cucumber-js/issues/1489#issuecomment-820716265) around getting test cases from the file system? Also do you have an update on this 6 month old issue (@Aslak Hellesøy) I still haven't been able to resolve? If so a response on the issue would be much appreciated 🙂
*Thread Reply:* Issue updated @Aurélien Reeves and thanks muchly for your eye balls and grey matter on it!
*Thread Reply:* 👍
As soon as I have a couple hours to take a look on it, I'll do
*Thread Reply:* I'd expect with the "minimal reproducible example" you requested it should be minutes rather than hours @Aurélien Reeves? Thanks.
Hi all. How do I get my test output to display the passing test details as seen in the Cucumber School videos? All I get are the results like this:
4 scenarios (4 passed)
17 steps (17 passed)
0m00.019s (executing steps: 0m00.007s)
Done in 2.71s.
In the videos, I see that sometimes mocha is executed. Is all I need to do is run jest on the files (I don't use mocha)?
I think I found it. I would have to set up a separate test collection as those found in /tests. That's overkill for the tutorial, but good to know as I move toward integrating Cucumber into my project.
What kind of detail do you want to output? The pretty formatter might be what you want https://www.npmjs.com/package/@cucumber/pretty-formatter
*Thread Reply:* Apparently, that's not a cucumber question. Probably a reporting feature in mocha.
*Thread Reply:* But I wasn't aware of the Prettier for Cucumber. So that's a good reference for later.
*Thread Reply:* To be more clear, I get output for passed steps IF I have a failing step. But if all pass, I simply get pass notification.
*Thread Reply:* Ahh. Now I see. The lesson on configuring cucumber with this formatter doesn't appear until later. I just arrived at it.
*Thread Reply:* Cool. This is exactly what I was looking for: ``` Rule: Shouts can be heard by other users
Scenario: Listener hears a message # features/hear_shout.feature:7
Given a person named Sean
And a person named Lucy
When Sean shouts "free bagels at Sean's"
Then Lucy should hear Sean's message```
Ping on release of fix for https://github.com/cucumber/cucumber-js/issues/1534 , looks like it has been addressed and merged into master but has not been included in a release yet.
@Jonathan Coombs we don't deliberately delay releases. Please be patient.
*Thread Reply:* What are the considerations for a release? Otherwise my question was asked due to ignorance.
*Thread Reply:* Typically when there is a consensus amongst the core team that we're ready for a release. We meet online on Thursdays to discuss. Then, if we feel a release is ripe, somebody has to spend time doing a bit of manual testing, write up release notes and make a release.
How do I represent the alternate path for required "givens"? I have 3 required form fields. Using Given, and, and... shows requirement. How do I write the scenario that says the submit button is not enabled until all three are selected?
Here is the scenario that needs help. I think I need conditional actions, but I'm not quite clear how to make this play correctly
Scenario: Enable the Add to Favorites button
When the consumer is viewing an item
And the consumer selects an item
And the consumer selects a size
And the consumer selects a quantity
Then the Add to Favorites button is enabled
Maybe in a Before() because the state and the actions all need to be true for all the subsequent scenarios. 🤔
Oh. I found the Background keyword. That may be what I was looking for. Nah. That's not quite it. I don't want all the selections to be true for each scenario. (continues trek up Mt. LearningCurve).
I refined it a bit. Still working on the negative use case. ```Background: Given the consumer selects an item
Scenario: Enable Add to Favorites button When the consumer selects the size and quantity options Then the Add to Favorites button is enabled```
@Michael Stelly a couple of little heuristics that help me write (and think about) gherkin steps:
Using those I'd tweak your latest iteration to this:
```Background: Given the consumer has selected an item
Scenario: Enable Add to Favorites button When the consumer selects the size and quantity options Then the Add to Favorites button should be enabled``` Honestly, this kind of low-level UI logic is something I'd probably not use Gherkin for. I'd rather use a unit test for the UI component, but that's not the question you're asking 🙂
That makes sense. I remember from my last foray into BDD that my thinking was not abstract enough. That's a good call out. Thanks.
So, the behavior would be what? That's what I'm trying to work out in my head. BTW, I'm playing as all 3 amigos because I'm creating a demo for the scrum team.
My struggle right now is understanding what is the behavior (declarative) that drives implementation (imperative).
As a consumer who is shopping on the App, I'd like the ability to favorite items that I maybe interested in.
Would this be more declarative? @matt-SmartBear
*Thread Reply:* So my current iteration looks like this ```Background: Consumer is shopping Given the consumer is shopping on the app
Scenario: Favorite an item When the consumer finds a desired item Then the app should allow the consumer to add it to the favorites list``` No buttons, no checkboxes for size/quantity. Just adding something to a list.
*Thread Reply:* The Given step is not using past tense though, which might be a signal something's wrong.
*Thread Reply:* Remember you can specify Rule: now in Gherkin too. Cleaving between rules and examples is a really important part of this process.
*Thread Reply:* The entire feature looks like this: ```Feature: Add item to Favorites
As a consumer (guest or member) who is shopping on the App, I'd like the ability to favorite items that I maybe interested in.
Rule: Any consumer, guest or member, can favorite an item after selecting a size, quantity, and shipping method
Background: Consumer is shopping Given the consumer is shopping on the app
Scenario: Favorite an item When the consumer finds a desired item Then the app should allow the consumer to add it to the favorites list``` Let me think on the "given is past tense" comment
*Thread Reply:* I wonder if you need more stuff like a given to set up the state that there is a "desired item" in your database somewhere for them to find.
*Thread Reply:* I don't think that's implicit in "the consumer is shopping on the app"
*Thread Reply:* As I mentioned, this is a PoC to introduce BDD to a naive audience - the product team.
*Thread Reply:* I like your scenario title. Follows the "Friends episode" heuristic nicely.
*Thread Reply:* I want to keep it light on details so that I don't overwhelm them. In terms of our crawl/walk/run stage, we're not even on our hands n' knees, yet.
*Thread Reply:* Would a better "given" be Consumer opened the app? That seems trite and empty. I'm a bit confused on where to draw the line between the declarative behavior and the imperative implementation.
*Thread Reply:* Have you added any automation under the hood yet?
*Thread Reply:* No, this is the very start of our foray into BDD. I'm still trying to get a grasp of the concepts. Here's my revised background.
Background: Consumer searched the product inventory
Given the consumer searched the product inventory
I'm viewing the Cucumber School videos and trying to apply the concepts to this selected feature as a real-world example.
*Thread Reply:* The magic of Gherkin is that it sits on the problem/solution domain boundary. You're working hard here to make it work in the problem domain, but I think you've started to spin the wheels a bit as you haven't had any feedback from the solution domain yet.
I'd suggest at least thinking about how you'd automate each of these steps, and then consider whether you've missed any additional steps that would be necessary to actually automate the whole scenario (assuming empty state in the system at the beginning), and then how you would express those in a way that makes sense in the problem domain.
*Thread Reply:* I have a rudimentary start to that, like the beginnings of a Consumer and Network class. This is very much the "fix (enhance) the car while driving it" situation. The app in question is a live production mobile app. All the infrastructure and supporting data are already in place. Add to Favorites is a completely new feature which is why I selected it for the demo.
As the only proponent of BDD in the organization, I have to rely completely on outside help like this forum, videos, tutorials and whatever else I can glean from the internet, to guide me. Your help is invaluable.
*Thread Reply:* Of course, now this begs the question: what are the feature boundaries? How difficult is it to start using BDD for an already mature, production app?
*Thread Reply:* I found the SmartBear youtube channel. This webinar outlined all the points you were helping me understand. Hope it can help others. https://youtu.be/awwFfCYoGFQ
*Thread Reply:* Ha nice one! @Jo Laing I guess we need to do a better job of signposting people to these videos. (Or we could re-publish them on school?)
*Thread Reply:* While we're talking youtube there's also a Cucumber channel with a lot of interesting talks from our conference:
https://www.youtube.com/channel/UC0eV4MhnmCd-48XdDhzf6Hg
thats your connextra at the top. That has "less" of a stylistic feel as that's something that often will come / be driven by your business people (BA/PO)
so as an example (Whilst we didn't have this at a previous job), we could have had connextras that featured phrases such as
Hi, Is there anyone who has experience with the WebdriverIO custom reporter? Or with CucumberJS reporter? I would like to integrate the Cucumber test results into the Testrail, but I am stucked a little. I installed babel when I initialised the wdio project and I followed this instruction: https://webdriver.io/docs/customreporter but I am confused now: ```import WDIOReporter from '@wdio/reporter' ^^^^^^
SyntaxError: Cannot use import statement outside a module```
*Thread Reply:* I don't think this is an issue with either of the reporters.
Before you use imports you need to make sure that, at the starting point of your code execution, you have Babel. Since wdio launches from the conf file, that is where you want to put it. So you will need a require here, but no-where else.
In wdio.conf.js include the following:
// this allows wdio.conf.main.js to use es6 imports
require("@babel/register")({
presets: ["@babel/env"],
});
module.exports = require("./wdio.conf.main");
Put what you would normally have in wdio,conf.js in wdio.conf.main.js (or whatever name you find appropriate, just match it to the require in the file above.
You should be able to use es6 imports everywhere in your code after that.
*Thread Reply:* I uploaded my project here: https://github.com/peterzsilak/wdio-cucumber-testrail/tree/add_cucumber_reporter I can use imports in other files… Can you please check my code?
*Thread Reply:* Well, I just cloned it (I'm actually curious about the Testrail integration, it's something I have thought about but never looked into). But I should be working right now. Can you first try implementing my suggestion? It is a tip I got straight from the WebdriverIO community after much wrangling with this issue, I am confident it will resolve your issue.
*Thread Reply:* Sure, I did, but and now I have a new error:
Error: Type check for option "reporters" failed: a reporter should be either a string in the format "wdio-<reportername>-reporter" or a function/class.
*Thread Reply:* I committed the changes, if you want to check it. 🙂
*Thread Reply:* Do you have something like
// Test reporter for stdout.
// The only one supported by default is 'dot'
// see also: <https://webdriver.io/docs/dot-reporter>
reporters: ["spec"],
in your main wdio conf file?
Perhaps your reporter needs to go there.
*Thread Reply:* I suggest the WebdriverIO gitter community if you're still stuck
*Thread Reply:* reporters: ['spec',
['CucumberTestrailReporter', {}]
],
*Thread Reply:* [0-0] 2021-06-09T14:10:40.165Z INFO @wdio/local-runner: Run worker command: run
[0-0] 2021-06-09T14:10:40.361Z DEBUG @wdio/config:utils: Found 'ts-node' package, auto-compiling TypeScript files
[0-0] 2021-06-09T14:10:40.682Z DEBUG @wdio/local-runner:utils: init remote session
[0-0] 2021-06-09T14:10:40.684Z ERROR @wdio/runner: Error: Type check for option "reporters" failed: a reporter should be either a string in the format "wdio-<reportername>-reporter" or a function/class. Please see the docs for more information on custom reporters (<https://webdriver.io/docs/customreporter>)
[0-0] at Object.validateConfig (/Users/pzsilak/Projects/ReachAndAttract/wdio_cucumber/node_modules/@wdio/config/build/utils.js:68:27)
[0-0] at Object.remote (/Users/pzsilak/Projects/ReachAndAttract/wdio_cucumber/node_modules/webdriverio/build/index.js:48:29)
[0-0] at Object.initialiseInstance (/Users/pzsilak/Projects/ReachAndAttract/wdio_cucumber/node_modules/@wdio/runner/build/utils.js:64:30)
[0-0] at Runner._startSession (/Users/pzsilak/Projects/ReachAndAttract/wdio_cucumber/node_modules/@wdio/runner/build/index.js:216:70)
[0-0] at Runner.run (/Users/pzsilak/Projects/ReachAndAttract/wdio_cucumber/node_modules/@wdio/runner/build/index.js:66:34)
[0-0] at process.<anonymous> (/Users/pzsilak/Projects/ReachAndAttract/wdio_cucumber/node_modules/@wdio/local-runner/build/run.js:24:30)
[0-0] at process.emit (events.js:327:22)
[0-0] at process.EventEmitter.emit (domain.js:467:12)
[0-0] at emit (internal/child_process.js:903:12)
[0-0] at processTicksAndRejections (internal/process/task_queues.js:81:21)
[0-0] 2021-06-09T14:10:40.685Z DEBUG @wdio/utils:initialiseServices: initialise service "chromedriver" as NPM package
[0-0] 2021-06-09T14:10:40.744Z ERROR @wdio/local-runner: Failed launching test session: Error: Couldn't find plugin "CucumberTestrailReporter" reporter, neither as wdio scoped package "@wdio/cucumbertestrailreporter-reporter" nor as community package "wdio-cucumbertestrailreporter-reporter". Please make sure you have it installed!
[0-0] at Object.initialisePlugin (/Users/pzsilak/Projects/ReachAndAttract/wdio_cucumber/node_modules/@wdio/utils/build/initialisePlugin.js:41:11)
[0-0] at BaseReporter.initReporter (/Users/pzsilak/Projects/ReachAndAttract/wdio_cucumber/node_modules/@wdio/runner/build/reporter.js:152:37)
[0-0] at Array.map (<anonymous>)
[0-0] at new BaseReporter (/Users/pzsilak/Projects/ReachAndAttract/wdio_cucumber/node_modules/@wdio/runner/build/reporter.js:22:50)
[0-0] at Runner.run (/Users/pzsilak/Projects/ReachAndAttract/wdio_cucumber/node_modules/@wdio/runner/build/index.js:77:26)
[0-0] at processTicksAndRejections (internal/process/task_queues.js:93:5)
2021-06-09T14:10:40.771Z DEBUG @wdio/local-runner: Runner 0-0 finished with exit code 1
*Thread Reply:* " Error: Couldn't find plugin "CucumberTestrailReporter" reporter, neither as wdio scoped package "@wdio/cucumbertestrailreporter-reporter" nor as community package "wdio-cucumbertestrailreporter-reporter". Please make sure you have it installed!"
*Thread Reply:* I see it also directs you here https://webdriver.io/docs/customreporter/
*Thread Reply:* So if that isn't enough to figure it out, again I would suggest the WebdriverIO Gitter community
*Thread Reply:* Look, I don’t understand this resolution…. when I installed the wdio I installed Babel also… And everything was okay, just this reporter did not wanted to work…
*Thread Reply:* I don't think I would be able to help further without really digging into it; it's not something I have worked on 🙂
*Thread Reply:* Okay, and thanks for your help,… I will look around in WebdriverIO Gitter. 😉
I have a nearly identical pair of scenarios. The only difference is whether the actor is logged in or not. So has/has not logged in, and status changes from guest to member. Insert phrase accordingly. Rather than write two separate scenarios, how can I simplify this?
Scenario: Favorite an item - member
Given I have logged in
And I have searched the product inventory
When I find a desired item
And I choose a size
And I choose a quantity
And I choose a shipping method
Then the app should allow me to add it to my member favorites list
Can I tidy up the When section? Would I use an example table for log in and status?
*Thread Reply:* • You could simplify the When section (yes). For example, you could obfuscate the size / quantity / shipping method details and move that logic to your helper steps, especially if the details are "incidental" to the test.
• You could use an example table.
*Thread Reply:* Ok. They're not incidental. They are pre-reqs. Before an item can be "favorited", all 3 -size/qty/ship values - must be chosen.
*Thread Reply:* Maybe I can say something like "when pre-reqs are selected" bc, who knows, maybe they could change at some point.
*Thread Reply:* Like this:
When I find a desired item
And pre-requisites are selected
*Thread Reply:* Sure, or even tweak the language slightly so it's just one step. "When I select a desired item with specified characteristics"
*Thread Reply:* You don't want that to get complicated though. The point being, what we're really testing is "adding the item to favourites" and we don't really care what the specific items are that we need to do before that, which, as you stated, could change (when that happens, you can change the implementation code, but would no longer need to change the scenario)
*Thread Reply:* Right. The scenario should indicate that there are conditions that must be in place before I can succeed.
*Thread Reply:* and that should be enough. What the conditions are, is not relevant here.
*Thread Reply:* The interesting thing about distilling steps like this is you have to find a name for the distilled concept. You've used "pre-requisites" here, for example. That then becomes part of your domain language.
*Thread Reply:* It's useful to check in with your domain-experts to make sure they like the terminology and buy into it.
*Thread Reply:* I think the Example table goes along with the Scenario Outline, doesn't it? 🙂
*Thread Reply:* yes sorry, they are a pair. I missed your comment earlier.
Hi, I have a json report that I'd like to feed in for a HTML report. I have given npm install multiple-cucumber-html-reporter
I have a json file under my repository. Could anyone please share the steps and commands I need to execute?
Any help would be appreciated! Thanks!!!
*Thread Reply:* I hadn't seen that multiple-cucumber-html-reporter package before. It's not something we maintain so unless another user or the maintainer are hanging out here you're going to be on your own 😞
There seems to be quite good docs at https://github.com/wswebcreation/multiple-cucumber-html-reporter#readme
What have you tried already?
*Thread Reply:* I'd like to export my cucumber tests in a report format (preferably HTML). That's my scenario. I don't have much inputs or commands for it yet and I'd like some inputs
Hi everyone - @cucumber/cucumber 7.3.0 is out! https://twitter.com/cucumberbdd/status/1405632173563170825
*Thread Reply:* If i give npm install @cucumber/cucumber
How will I execute my feature file?
Is it ./node_modules/.bin/@cucumber/cucumber or how do I execute it?
*Thread Reply:* (Normally there shouldn't be any files called ./node_modules/.bin/@cucumber/cucumber)
You can also add this to your package.json:
{
"scripts": {
"test": "cucumber-js"
}
}
And run npm test (npm autimatically adds ./node_modules/.bin to your PATH)
*Thread Reply:* I use something similar
"scripts": {
"test": "cucumber-js -f @cucumber/pretty-formatter"
}
Then run yarn test from cli
Also, I've a test.feature and test-report.json file. What input should I give in html-formatterto generate a html report?
I went through the github repo but it has tons of info that I could understand..How should my command be?
*Thread Reply:* Use cucumber-js --format html:cucumber.html
Also see cucumber-js --help for full help about the command line options.
*Thread Reply:* (This should create a cucumber.html report in your current directory)
*Thread Reply:* There's also --publish which will create a HTML report automatically at https://reports.cucumber.io
Hello all, I posted this is #help but I think it better suits here. I am new to Cucumber-js and
I am trying to use --world-parameters in Cucumber-JS like that npx cucumber-js .\qa\features\login.feature --world-parameters '{\\\"config\\\":\\\"qa\\\"}'
When using console.log(this.parameters.config); inside my step or Hook, I get 'undefined' .. Do you know if I should use it some other way.
*Thread Reply:* Hi @Mohamed Soliman are you also using `setWorldConstructor`` to use a custom class for your world?
*Thread Reply:* nope.. I just need the basic world to pass variables from CLI to stepdefinitions
*Thread Reply:* Are you using arrow functions or regular functions for your hooks/steps?
*Thread Reply:* In general, if you use arrow function, this will not have the value of your world object.
*Thread Reply:* There isn't anything we can do about this in Cucumber.js - it's a feature of the JavaScript language:
> Arrow functions establish "this" based on the scope the Arrow function is defined within.
*Thread Reply:* it worked upon changing to normal function..
*Thread Reply:* but it was not clear when reading through world.md document, I was trying for a whole day and it was not mentioned anywhere
*Thread Reply:* You should have asked sooner 🙂 - I'll add a note about this in the docs.
*Thread Reply:* Just noticed it's the first question in the FAQ: https://github.com/cucumber/cucumber-js/blob/main/docs/faq.md#the-world-instance-isnt-available-in-my-hooks-or-step-definitions
*Thread Reply:* oh yes.. I missed it while searching.. Thanks, sir
*Thread Reply:* But it's easy to miss, so I'll add some more mentions of it 🙂
*Thread Reply:* @Mohamed Soliman hopefully this makes it clearer!
*Thread Reply:* https://github.com/cucumber/cucumber-js/pull/1705
*Thread Reply:* For what it's worth it stumped me as well at first. I mention this in the commands of my tester's documentation for the benefit of my other team members.
I would like to launch cucumber like this npm test -- --show-browser During my Before step I would read the command line args and have Puppeteer display the GUI if that flag is present. I know how to do this, but I need help figuring out how to stop Cucumber from erroring out because it saw an unrecognized option flag.
*Thread Reply:* I've built a wrapping file to start my cucumber tests already. It can read the command line arg before the cucumber library even loads, but can I remove the arguments I've handled from the argv line? I've looked into cucumber deeply enough to know it's using commander as its cli reading dependency.
*Thread Reply:* Another tact would be to expand the capabilities of cucumber to allow the test writer to register additional command line flags.
*Thread Reply:* Also note - I'm well aware of profiles and they are very powerful. I use the world parameter to feed puppeteer its basic parameters already - mostly which device to emulate. BUT the showbrowser mode is something I would want to be able to turn on with any profile, so I can't really make it active in certain profiles. I also don't want to ask my users to edit the cucumber.js to turn the browser GUI on or off.
*Thread Reply:* Or maybe this is possible by working with Commander directly in the program flow...
*Thread Reply:* Ok, I have a solution. I can look for my custom flags before starting Cucumber, and if I see them slice them out of the argv array like so:
if (process.argv.indexOf('--show-browser') > -1) {
process.env.headlessBrowser = false;
process.argv.splice(process.argv.indexOf('--show-browser'), 1);
} else {
process.env.headlessBrowser = true;
}
*Thread Reply:* Later in the same file I then hand off process control to Cucumber like so:
require('@cucumber/cucumber/bin/cucumber-js');
*Thread Reply:* I really wish that hand off mechanism was documented somewhere.
*Thread Reply:* We don’t really have a programmatic API for running cucumber at the moment, this is something we’re going to be working on shortly.
I believe you can repeat the —profile arg and the profile contents are merged. World parameters are also merged together. So could have a profile that just adds your showBrowser option as a world parameter, and this could be activated in conjunction with any other profiles. So you could use that pattern to effectively build up custom CLI options by way of composable profiles.
*Thread Reply:* or you could use an environment variable? That's what I usually do for this kind of thing.
Big thanks for working with us to get https://github.com/cucumber/cucumber-js/issues/1489 over the line @Aurélien Reeves !
*Thread Reply:* Great work @Aurélien Reeves and @binarymist 🙌
Anyone have experience dealing with writing tests for core code and allowing extending code to also be tested? Of particular issue is with defining steps. I want to load the steps of my child project first, then look over the steps of the parent project and only define the undefined steps. Then I have to write the code in such a way that parent steps can be overrode.
*Thread Reply:* There wouldn't happen to be a "definitionExists( pattern )" function in the api would there? If there is great, if not I fear I'll need to write my own define step function that keeps track of what is and isn't defined.
https://twitter.com/cucumberbdd/status/1410980312939745287
*Thread Reply:* This is wonderful, thanks to everyone who put work into creating and publishing this!
I can't wait to give it a try.
I have two thoughts.
*Thread Reply:* This might even inspire me to finish off that blog post series...
Can someone refer to a good online course on CucumberJs which uses Page Object Model please?
*Thread Reply:* const { defineStep } = require("@cucumber/cucumber"); const readline = require("readline");
defineStep('pause', {timeout: _1}, async function() { const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); return new Promise((resolve) => { rl.question("Pause Step in Gherkin. Press Enter to Continue.", () => { rl.close(); resolve(); }); }); });
*Thread Reply:* So what this step does is pause cucumber. Useful for tests using Selenium or Chromium where you want to see what's going on in the browser, maybe click around a bit and check things.
Just re-posting this here in case anyone can help with a cucumber js specific issue.
*Thread Reply:* Are you validating that the db is cleared when the before step runs?
*Thread Reply:* @catharsisjelly maybe you're missing an await in your Before hook or something?
*Thread Reply:* @Cat No I assumed it was done, I'm used to PHP more so a few JS things are tripping me up
*Thread Reply:* @matt-SmartBear My Before function hook looks like this if it helps
Before(function () {
for (let collection in dbConnection.collections) {
dbConnection.collection(collection).drop()
.catch((e) => {});
}
});
*Thread Reply:* I figured dropping the collections was the fastest way to truncate them
*Thread Reply:* Do you need to await the call to drop()? Does it return a promise?
*Thread Reply:* it does, I have tried it with an await too and still errors.
*Thread Reply:* My guess is that's what's going wrong - it's a timing issue that means Cucumber has started the scenario before the drop() promise has resolved.
*Thread Reply:* Can you show us what it looks like when you use a promise?
*Thread Reply:* Yeah I was thinking the same thing... You want to see the output or code?
*Thread Reply:* Oh.. maybe jest is trying to run 2 features concurrently...
*Thread Reply:* If each feature runs fine all by itself that makes sense that itt might not if the second feature is running at the same time
*Thread Reply:* Yeah that will definitely cause yo problems if there is shared state
*Thread Reply:* Not sure how to set that up using jest and cucumber-jest but I'll dig through some docs. But for now here is that Before function with the await
Before(async function () {
for (let collection in dbConnection.collections) {
try {
await dbConnection.collection(collection).drop();
} catch (err) {
// collection does not exists, so iit does not matter that it was not dropped
}
}
});
*Thread Reply:* That looks good to me. That should at least mean that two consecutive scenarios don't clash in the database. If you have concurrent scenarios running though, that's a different problem.
FWIW I think you could also use map to turn the collections array into an array of drop promises, and then return Promise.all of that, to make your code more concise.
*Thread Reply:* It is possible to keep running scenarios concurrently, but you'll need to make sure everything going into the database has a unique ID,
*Thread Reply:* think about each scenario as a user working on your app - if you want them to be able to hit the app in parallel, you need to partition their data.
*Thread Reply:* Yeah that helps thanks @matt-SmartBear It's slowly dawning what might be the issue. No idea how to fix iit yet but thats half the issue.
*Thread Reply:* @matt-SmartBear for the map thing, do you have any docs links I could read up on how that works, it's not a JS concept I'm aware of
*Thread Reply:* Not sure of a good link for this. Here's how I think the code might look:
Before(
() => Promise.all(
dbConnection.collections.map(
collection => dbConnection.collection(collection).drop()
)
)
)
*Thread Reply:* Essentially, if drop() returns a promise, you can use map to turn the array of collections in to an array of promises to drop those collections. Then you can use Promise.all to turn that into a single promise that all of the collections have been dropped. Then you can give that single promise to Cucumber as the thing you want it to do before it runs a scenario.
*Thread Reply:* Yeah just reading the Mozilla docs on Promise.all
*Thread Reply:* I have some code that wraps around cucumber - it starts go hugo server and cucumber in child processes and shuts down the hugo server when the cucumber thread finishes. It also has Puppeteer js getting started and stopped and an API mocking server built on express. It's solid, but a bit complex and it has a few command line flags. I am currently writing cucumber tests of those flag using root cucumber - and it's working so I have the situation of a cucumber running in a cucumber.
What is that called though? 🙂
*Thread Reply:* Joking aside, my inner cucumber process isn't emitting any output but the .'s. My console log statements are being lost.
Hmm.. I'm running into trouble writing tests of the command line. I have written a cucumber test that can take log-level, device, language and debug flags off the command line, and I'm trying to write a cucumber test that runs the customized cucumber runner on the command line. I'm very close to getting it working, but I'm having trouble getting information out of the inner process to the outer one for examination. I've tried process.send / on.message - doesn't work. The console.log messages of the inner cucumber process are being suppressed even though I have { stdio : 'inherit' } set on the process. Oddly, I am getting output from the grandchild go hugo process, but that doesn't help. I've tried writing output to a file, and that works when the child process is alone, but isn't working when the child is invoked directly.
How does cucumber test it's own cli options? I'm guessing my solution is somewhere in the exiting codebase.
*Thread Reply:* We do this: https://github.com/cucumber/cucumber-js/blob/main/features/support/world.ts#L53
*Thread Reply:* It will take me awhile to parse through it and understand it, but yeah, looks like what I need.
*Thread Reply:* Took a couple days but this did work. The largest problem points to something that might be addressed in Cucumber core.
*Thread Reply:* The tester was thrown off by a parameter being '"@devices"'
*Thread Reply:* Perhaps the parsing of the tags arg should silently toss extra quotes?
the world constructor is acessible to steps and hooks. how to use pom and have the world acessible in pom classes as well?
*Thread Reply:* A simple way is to have your page object classes take your World as an argument in their constructor. Then you can new them up from steps/hooks (or, manage the creation of page objects with your World itself)
*Thread Reply:* hmm i have taken the same approach. thanks for help
a common question: are you folks testing in chrome or chromium.Mostly modern node js tool support chromium and not chrome.Need some inputs on how others are testing
*Thread Reply:* I’ve been testing in chromium. Not sure if you’re asking generally or want to hear from the dev team. I’m just a user.
Guten tag! "Guys" is easily replaced with the more gender-neutral "Folks" or "All". We'd appreciate if you tried to use that. Thanks!
Question about VSCode JS function go to definition(F12) feature. Inside step definition, that feature doesn’t work. Is that something we know? Or it should work?
That feature works in other js file in the project. Only not work inside step definition.
Do you know how it works? Maybe you need to configure it to scan the features folder? Where is the waitForElementVisible function defined? What folder is that in?
*Thread Reply:* @matt-SmartBear You are right, actually it works. Only not work with the nightwatch.js commands. I will check that. Thanks!
So, would anyone be interested in seeing the trickery I came up with to get Cucumber-js to fully support being run under esm so that the tests can be written using ES6 modules?
*Thread Reply:* sounds good - been working on https://github.com/cucumber/cucumber-js/pull/1649 so interested to compare
*Thread Reply:* I'll look at that branch in detail tonight after work.
*Thread Reply:* At a glance though that functionality will let me simplify my code stack further.
*Thread Reply:* Cause for the most part I'm running cucumber in a child process using node -r esm path/to/cucumber/
I think I might be able to extract it out into a cucumber-esm module for general use.
A while ago github used to show the progress of the steps - that …… as the tests were running. It no longer shows that, even when I’m on the action page when the tests start. Does someone know how I can get that back?
*Thread Reply:* I've never noticed that feature
Which CI are you using? If using github action, which action are you using?
*Thread Reply:* [It is and has been a github workflow.] The only external actions I’m using, or have ever used, before the tests are:
uses: actions/checkout@v2
uses: actions/setup-node@v1
*Thread Reply:* [We are making] a framework that uses cucumberjs for some of its functionality. The start of the script in package.json is ./node_modules/.bin/cucumber-js --require ./lib/index.js. @Aurélien Reeves
*Thread Reply:* When do you say that it showed the progress of the steps, what do you mean exactly? Would you have a screenshot?
*Thread Reply:* I don’t have a screenshot, sorry. Didn’t know I’d need it 😉 You can see it in your terminal when you run it locally, though. As I said, it’s the little progress dots that appear - one for each step.
*Thread Reply:* ☝️ @Aurélien Reeves. Sorry for the late reply. Slack doesn’t color the dot red if my username isn’t used.
*Thread Reply:* @plocket are you talking about the progress formatter which shows dots on the console when executing tests? The thing that looks like the following:
```$ node ./bin/cucumber-js --format=progress ................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
264 scenarios (264 passed) 1356 steps (1356 passed) 0m45.247s (executing steps: 0m33.205s)``` And they have disappear from your github workflow logs? In some place like on the screenshot attached?
*Thread Reply:* Exactly, @Aurélien Reeves! That’s exactly it. I no longer see the dots on the github workflow logs.
*Thread Reply:* And thanks for the ping. It’s been a crazy day and I wouldn’t have noticed at all.
*Thread Reply:* Those dots are written to the console with the progress formatter.
Check the formatter(s) you are using within your workflow. If you want the dots back, make sure to add the progress formatter.
You can do that with command line arguments, but also with profiles.
Documentation for the profiles: https://github.com/cucumber/cucumber-js/blob/main/docs/profiles.md
Note: the progress formatter is not the same one than the progress-bar formatter.
*Thread Reply:* I haven’t had a chance to look into this, but I did find that when I inserted console logs in the middle of the steps, the progress dots would appear as soon as the first console log happened. It makes me think this is a setting in github. Something about log levels or something. Maybe process.stdout.write doesn’t appear during the test run, while console.log does for some reason.
*Thread Reply:* Do you want to show the progress from the github action in real-time? Do you have any issue with the progress formatter when executing the tests on your own computer?
*Thread Reply:* I do want to show the progress in real time. Local tests show progress just fine.
*Thread Reply:* Ok, thanks for the explanation.
This seems related to github, not to cucumber, specially if you are not encountering issues locally.
I guess github action logs are streamed one line at a time, when a new-line character is encountered. The progress formatter does not put new-line characters, so github action logs are not streamed in realtime.
You see some progress when you add some console.log because it will put a new-line character
*Thread Reply:* You may consider using your own custom formatter. You may override the buil-in progress formatter and add new-line characters in addition to the dots. That should trigger the stream from github in "real-time"
*Thread Reply:* We’ll put that in the issue to try. Does your GitHub show the progress?
*Thread Reply:* As seen on the screenshot from last time, yes, it does
*Thread Reply:* Ah, ok. That looked to me like progress dots after everything was done, not while the workflow was running. 👍
*Thread Reply:* Oh, you meant the progress!? I guess not. As I said, GitHub shows logs per line, when it detect a new line character
*Thread Reply:* Ok. Yeah, the new line thing happens to you too. That seems like it’s related to cucumber as well as GitHub, then, since cucumber isn’t putting a new line at the beginning of logging progress.
Does someone know where I can look for more information about the above? ☝️
Can cucumber --retry success rate be logged into the report? For example, I set --retry 2 , it will rerun 2 times after fail. If I have 1 time passed and 2 failed, I will get pass on the report. That’s fine. However, after I read this https://automationpanda.com/2021/06/14/are-automated-test-retries-good-or-bad/, I think to have a success rate on the report(like the picture) will be a nice to have. In current cucumber json report, I couldn’t see any data relevant to the retry.
*Thread Reply:* I think there won't be any retry after one success. So you won't have more than one success.
For example if you have --retry 10, one test fails on the first attempt, if it succeed at first retry, it won't retry anymore.
*Thread Reply:* Thanks @Aurélien Reeves . Sorry for the confusion, what I mean should be first two tries failed, and third passed.
*Thread Reply:* If that 1/3 pass success rate can be reported, it will help us to find out flaky issues.
*Thread Reply:* Or at least the number of failed attempt
That is interesting. I suggest you submit a feature request: https://github.com/cucumber/cucumber-js/issues/new?assignees=&labels=&template=feature_request.md&title= 🙂
*Thread Reply:* If it’s not a feature yet, happy to submit the request. Thanks @Aurélien Reeves!
*Thread Reply:* I am not sure actually, but I don't think it is a feature yet.
And it may depends also on which formatter you may request that feature. Some formatters are commonly used by severals implementation of cucumber, but the retry mechanism is not, so there may be interesting incoming discussion 😛
That would be easier to follow on a github issue than in a thread on slack 🙂
*Thread Reply:* FYI you're not using the default html formatter, you're using something like a jenkins one, so you'd need to go there for that.
*Thread Reply:* Hi @luke that image is just from the article I linked. I am using https://github.com/gkushang/cucumber-html-reporter and checked in https://reports.cucumber.io/. Didn’t see the retried details.
*Thread Reply:* Do you mean it’s supported in cucumber default HTML formatter?
*Thread Reply:* https://github.com/cucumber/cucumber-js/issues/1739 For further discussion.
*Thread Reply:* Thanks @Tim Yao 👍
As you noticed: this request is related to formatters.
On Cucumber we may address some of our own ones, but when using other formatters like the one from gkushang, you should also ask them too.
*Thread Reply:* Yes. gkushang one is based on the deprecated json formatter, so I think I may switch to core html-formatter in the future.
*Thread Reply:* If there are features in the gkushang one you like that we're not implementing yet, we'd love to hear about it!
*Thread Reply:* Thanks @matt-SmartBear will try and see what is the difference
Hi I am using playwright with cucumber. checking out this repo https://github.com/cucumber/playwright.js/tree/main/features. however can someone tell me how I can run the test?
*Thread Reply:* Do you want to execute the test of the playwright.js repository?
*Thread Reply:* If so, try npm test
To execute the tests you are setting-up using cucumber and playwright.js, execute cucumber as usual
*Thread Reply:* Hi @LayMui don't get fooled by the name - it has nothing to do with the Microsoft Playwright library. See https://github.com/cucumber/playwright.js/issues/31 - we might rename it back to @cucumber/screenplay.js
I've been given permission to spend at least some of my worktime working on open source projects my company is using, Cucumber being chief among them. Simplifying ESM stands out and I've been pointed to the existing project and would like to join that effort. The last major Open Source project I worked with was Drupal. Do y'all have a page that lists out the ES-lint settings to use as well as any other pull request policies? Basically a getting started for contributors page?
*Thread Reply:* maybe https://github.com/cucumber/cucumber-js/blob/main/CONTRIBUTING.md is what you are looking for?
*Thread Reply:* Great news @Michael Morris!
Sadly we do not have a great contributor/developer documentation yet 😞
There is an on-going effort to improve documentation for new contributors. At the moment it was focused on cucumber-ruby and on the "welcoming" documents like README and CONTRIBUTING.
We have an issue to exchange ideas on that topic: https://github.com/cucumber/common/issues/1521
What kind of documentation were you looking for? Would you have some links to existing ones in other OSS projects as reference?
You can submit your suggestions, ideas and request in the issue, that will be easier to keep track later 👍
*Thread Reply:* That's fantastic @Michael Morris!
One of our goals for the year is to increase the number of new contributors, so anything you find difficult, confusing, or even just a little bit annoying as you take your first steps, we'd love to hear about it.
I'm available for 1:1 mentoring if you'd like some pairing time. https://calendly.com/mattwynne
*Thread Reply:* FWIW, the place to start contributing for any github repo should be https://github.com/cucumber/cucumber-js/contribute
That page will show the contributing guide, and any issues tagged with "good first issue".
God dag! "Guys" is easily replaced with the more gender-neutral "Folks" or "All". We'd appreciate if you tried to use that. Thanks!
Hey! I am migrating to cucumber-js 7.3.1 and can see that setDefinitionFunctionWrapper is being deprecated in v8. At the moment I use this to handle scenario timeouts (I am running tests inside an AWS lambdas). Been looking at the new BeforeStep hook, but I'm not sure I can replicate the desired behaviour with that... Has anyone achieved something similar?
Was thinking perhaps might be able to use setDefaultTimeout within a BeforeStep hook, but seems this timeout value is evaluated before execution and updates to it are not respected.
*Thread Reply:* If other users are looking into this, we have discussed this issue here: https://github.com/cucumber/cucumber-js/issues/1741
Is there a way to share state between an entire suite of tests as they run (vs on a per-test basis)? Currently running into a limitation due to a script that I can only run before test runs.
*Thread Reply:* I need it to be set during the first test and remain afterwards
*Thread Reply:* I am using nightwatch.js with cucumber.js, I use nightwatch globals to manage state.
*Thread Reply:* Looks like a selenium alternative, not something I'm looking for ATM.
My best thought so far is to disable this new setup stuff until we've integrated the work being done in the pre-test script so that it can be run on demand, so we no longer run into this limitation.
Which means the recent work needs to be left on hold.
😞
*Thread Reply:* Doesn't work: https://github.com/cucumber/cucumber-js/issues/1393
*Thread Reply:* It will only work with Before hook, hence "per-test", which won't work with our current setup.
*Thread Reply:* In my use case, I have a global vars like test id, project name , also have some initialisation data as states to share across all tests.
*Thread Reply:* I also set test id to env var, so I can share the id across CI jobs.
*Thread Reply:* like multiple cucumber process can share the same test id.
*Thread Reply:* no, if I use env var, it’s set outside cucumber, like in CI job.
*Thread Reply:* Right, I'm looking for a way to • set a variable inside a beforeAll hook • have it carry over to next tests
*Thread Reply:* world is state within scope of a single scenario
*Thread Reply:* yep, that's exactly my issue, it won't carry to the next scenario
*Thread Reply:* this, inside a cucumber scenario, or even hooks usually refers to the world object, does it not?
*Thread Reply:* I haven’t use world yet, looks like this is point to world .
*Thread Reply:* By using global state, will it be a issue when we run cucumber parallel?
*Thread Reply:* I just have to find the JS alternative to boto3 / awssrp, something I should have done a long time ago 🤷
*Thread Reply:* ideally we need to do node js stateless way. as it’s not work for multiple node process.
*Thread Reply:* I see https://github.com/cucumber/cucumber-js/blob/main/docs/parallel.md cucumber-js --parallel 3 only shares env vars, not in memory vars, that can cause you lost the global state. My nightwatch global won’t work in parallel I guess. 🙃
*Thread Reply:* To solve that problem, need to put state management into a shared db.
*Thread Reply:* boto3 / awssrp is for storing state in AWS s3? that sounds a good solution for me.
*Thread Reply:* @Mona Ghassemi what do you think to the proposal in the issue you linked? ie to allow some state to be set in a BeforeAll which you can then read (not write) from scenarios - would that solve your need?
*Thread Reply:* @Mona Ghassemi you should be able to use process.env.SOME_ENV_VAR = "a-value" in your beforeAll hook, and then read that later on, no?
*Thread Reply:* I’m surprised nobody has suggested using global variables yet. That’s a JavaScript thing, not a Cucumber thing.
*Thread Reply:* @Aslak Hellesøy I think you are talking about using global object like global.myTestState . I tested it, works. I think it’s same as my Nightwatch.js globals data. However, I guess it may not work in parallel. As it’s in the memory, not able to be sync between parallel processes. Haven’t test it yet.
Hello all. Can anybody help with the Allure report configuration in Jenkins. We can get a local report with no problem. We’ve followed the manual but can’t get it. Any help will be greatly appreciated. We use Cypress and Cucumber pre-processor
*Thread Reply:* Can you share more about what you've tried, and what specific errors or other problems you've encountered?
Hello, how does the parallel execution work? Does a worker execute random scenario or is this per file like jest does it?
*Thread Reply:* Yep it’s per scenario - once we get to actually running tests, which feature file it’s in doesn’t mean much.
*Thread Reply:* If you’re interested, someone is working on a way to control the allocation of scenarios to workers.
*Thread Reply:* https://github.com/cucumber/cucumber-js/pull/1588
Is there a way for me to have access to the cucumber report link in my CI (Github actions) to forward the output to Slack or otherwise? I'm finding it's getting a bit tedious to click through. Perhaps the old way of creating a json or xml report and piping that into Slack? Curious if anyone has a workable solution. Thanks!
*Thread Reply:* I have a feeling it's not super straightforward as that message "View your Cucumber Report at:..." is sent back verbatim from the reports server, so there's no structured data with the URL in it. I night be wrong though, but I think I've asked the same question before.
*Thread Reply:* Thanks! If all else fails I think the old fashioned xml should be usable. Was hoping it would be easy-peasy-lemon-squeezy 🍋
*Thread Reply:* We have an open issue about this for Cucumber-JVM: https://github.com/cucumber/cucumber-jvm/issues/2324
If you’re using a different Cucumber implementation, please raise a corresponding issue.
*Thread Reply:* FYI: Cucumber issues a GET request first. The server responds with 204 and an upload URL in the Location response header, plus a plain text banner that cucumber prints after PUT ing the cucumber messages to the «pseudo redirect» URL.
You can find a bash implementation of the upload client here: https://github.com/cucumber/common/blob/main/scripts/publish-cucumber-report
*Thread Reply:* Thanks @Aslak Hellesøy! Yes, am using the js implementation so I guess I'll need to raise the issue. Will probably look into these internals a bit too when I get a chance!
Hello All. We are using Cypress. Typescript and Cucumber-preprocessor plug-in. Our code works but it looks like preprocessir makes our code run very slowly . Can anyone suggest sum Cucumber alternative for Cucumber with Cypress. Any help will be greatly appreciated.
*Thread Reply:* It might be worth raising an issue here https://github.com/TheBrainFamily/cypress-cucumber-preprocessor - AFAIK that plugin only uses very little cucumber stuff - just the Gherkin parser.
*Thread Reply:* @David Goss I understand but my question was about if there is an alternative to cypress-cucmber-preprocessor
Is it possible to append information to the messages sent to formatters? I want to include some data like the browser type my test is using. When running in a single process the formatter has access to the browser to find out, but when running in parallel the formatters don’t seem to have any information from the processes running the tests.
*Thread Reply:* Yes the formatters run on the coordinator and all the scenarios are running on the worker. You could this.log the information from a step or hook, which will emit an attachment. Also you might be interested in https://github.com/cucumber/common/issues/1317 which is about being able to emit custom stuff in the meta message, although again this would happen in the coordinator
Hi, I've been having difficulty attempting to run scenarios but "not" scenarios with a certain tag. Online I see ~@tag format and "not @tag" format. Neither seems to have worked for me, not sure what I'm getting wrong.
For example my run scripts look like:
"testNightly": "node -r dotenv/config ./node_modules/.bin/cucumber-js --tags='@nightly'",
Say I wanted to add a "not @notReady" to this. How would I structure that?
*Thread Reply:* Ah. Will try that, I think I was trying to do it like
@nightly, not @notReady
*Thread Reply:* Tag expressions are infix boolean expressions. There are no commas or other punctuation. https://cucumber.io/docs/cucumber/api/#tag-expressions
*Thread Reply:* Specifying only @nightly would be sufficient, unless you have scenarios tagged with both @nightly and @notReady. Why would you tag a @notReady scenario with @nightly?
*Thread Reply:* It's just a toy example, I don't have a @notReady tag.
*Thread Reply:* I didn't think through the example very hard but I do have cases where I want to exclude something 😄
Hi there, question for https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md#--no-strict
By default, cucumber works in strict mode, meaning it will fail if there are pending steps.
What is the benefit to fail pending steps? I guess it is set as default by some reason? Otherwise I feel pending means uncompleted tests should just be ignored instead of fail.
*Thread Reply:* I don't have the history of that, just a personal though: that could avoid forgetting about pending things
As a developer, at some point, I could totally forget about pending things, specially if they are totally ignored. However if they are responsible for failing my CI for example, I cannot ignore those
*Thread Reply:* Thanks @Aurélien Reeves that makes sense. In my case, I want to leave some test cases skipped based on the environment. For example, one test case works in most of browsers but not IE11, I may return pending for IE now and fix it in the future. However, I wish it can still pass CI in IE with this pending step.
*Thread Reply:* In your case, would "skipped" be more appropriate than "pending"?
*Thread Reply:* It is just because I don’t know I can return skipped … looking at the docs now
*Thread Reply:* Works like a charm! Thanks @Aurélien Reeves I will stick with skipped then.
*Thread Reply:* also for pending steps you can also tag the feature not to run (Which is probably better behaviour), it's what we do.
*Thread Reply:* @luke I do has tags like @skip then use it in cli tags like not @skip . But I see someone do it like this:
Before({tags: "@skip"} async () => {
return 'skipped';
});
So I don’t need to add not @skip to cucumber tags argument, is that a good practice?
*Thread Reply:* So there's a difference here, so if you do it that way, it'll return a cucumber skipped exception.
Now in my eyes, that is ok. So something then causing that to fail I wouldn't support. But I'm 99% certain that they aren't prohibited, just not defaulted.
*Thread Reply:* Because doing it dynamically on the fly also allows you to configure it based on params. Like we have a whole class that determines whether to skip a scenario.
*Thread Reply:* I get it'll return a cucumber skipped exception is the difference.
*Thread Reply:* And second way is dynamic may give me some flexibilities.
*Thread Reply:* irrelevant question maybe, how do you disable tests failed because defect?
*Thread Reply:* I tried to tag it @defect then use not @defect in command to ignore it.
*Thread Reply:* That looks like something very specific to your need, so using tags as you did looks good to me
*Thread Reply:* that tag does nothing. But we know every tag that has failing SHOULD have a ticket number assigned as well.
*Thread Reply:* I use a comment for that purpose. but tag sounds a better way.
Can somebody tell me how to publish test result from .json file into 'test' tab in Azure DevOps pipeline? Currently, junit test runner does not publish it to the 'test and the 'test' tab is not visible. My tests are written in typescript + Cucumber is + playwright.
@Tally Barak how can I change the tag to run only certain scenarios? for example I want to only run test scenarios with the @test tag? https://github.com/Tallyb/cucumber-playwright/tree/master/features
*Thread Reply:* You can do that exactly as you would with cucumber. For example you can use command line arguments: https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md#tags
Or you could also use specific profiles: https://github.com/cucumber/cucumber-js/blob/main/docs/profiles.md
*Thread Reply:* Using profiles
Or updating package.json to add your filter into the "test" script
Or you don't use npm run test, but npx cucumber-js with the --tag argument
*Thread Reply:* We use something like this:
node ./node_modules/.bin/cucumber-js --tags='@tagName'
*Thread Reply:* make it shorter with npx cucumber-js --tags-"@tagName"
*Thread Reply:* We use named scripts in the package.json btw, so like: scripts: { testWeb: node ./node_modules/.bin/cucumber-js --tags='@web', ... }
and then at command line:
yarn run testWeb
(or npm if that's what you use).
*Thread Reply:* I think I realized that my issue was that we use dotenv, but to be perfectly honest, I think I can remove it as the way we need to import variables per environment probably makes it redundant so we have ""node -r dotenv/config ./node_modules/.bin/cucumber-js --""
I will probably look at removing dotenv
@Tally Barak I tried to add new feature to your existing template on playwright-cucumber. it didn’t work. it give some undefined implementation steps. could you help shed some light? here is my repo https://github.com/LayMui/playwright-cucumber/tree/form-registration
*Thread Reply:* TSError: ⨯ Unable to compile TypeScript: src/steps/playwright.steps.ts:2:23 - error TS6133: ‘DataTable’ is declared but its value is never read.
2 import { Given, When, DataTable } from ‘@cucumber/cucumber’;
*Thread Reply:* my feature has datatable like this
Scenario: Fill up registration form
When he fill up his registration details
| username | age | residency | accounts | nationality |
| johnmark | 48 | resident | Savings | USA |
Then he is able to submit his form
*Thread Reply:* but it seem to affect the original step defn by you
@foo
Scenario: Change theme # features/playwright.feature:7
Given Go to the playwright website
? undefined
When Change theme to "light" mode
? undefined
Then Snapshot
- skipped
When Change theme to "dark" mode
? undefined
Then Snapshot
- skipped
Hi, I am not sure if this is cucumber.js, I got this error
☕ImplementationPendingError: Step implementation missing:
[test_form:execute] [0-1]
[test-form:execute] [0-1] Given('{actor} is at the embassy', function (actor) {
but I have defined this step in the step definitions
Given('{actor} is at the embassy', async (actor: Actor) =>
actor.attemptsTo(
<a href="http://Navigate.to">Navigate.to</a>('/')
)
);
not sure why it still complain missing step definition. here is the repo at config branch
<https://github.com/LayMui/serenityJS-cucumber-wedriverio/blob/config/features/step-definitions/form-registration.steps.ts>
Hello all, I am trying to clean my workspace a little. So, is there a tool or a cmd line that can let me know which steps of my step-defs file is no more used in feature files. I have been working on my posrtfolio for quite some time and I am sure there are a lot of steps are are no longer used. I need to clean them up. Can anyone suggest a solution
*Thread Reply:* The low-tech way would be search for the step def in the repository and see if you get other matches (depending on what text editor / IDE you have, there is generally a way to do it).
*Thread Reply:* this is very low-tech.. must be there’s a better option
*Thread Reply:* But thank you for suggesting it anyway
*Thread Reply:* Yeah I understand if you have a lot of features / code it's not ideal! But now I'm curious too. 🙂
*Thread Reply:* ~Maybe with some code coverage tool?~
Found that the usage formatter actually detect unused step definitsions
*Thread Reply:* The usage formatter - built-in with cucumber-js - is actually able to report unused step definitions.
https://github.com/cucumber/cucumber-js/blob/main/src/formatter/usage_formatter_spec.ts#L33
https://github.com/cucumber/cucumber-js/blob/main/features/usage_formatter.feature#L8
*Thread Reply:* it seems a good solution. Is there documentation for its usage from Docs or readme file?
*Thread Reply:* Formatter docs are a bit terse but I have some improvements in flight, see https://github.com/cucumber/cucumber-js/blob/docs-rework-formatters/docs/formatters.md#usage
*Thread Reply:* You probably want to use “dry run” at the same time so it doesn’t have to actually execute all your tests to find the usage
Hi folks, this is probably unusual, but... is it possible to override one of the build-in parameter types?
defineParameterType({
name: "string",
regexp: <custom regex>,
transformer: <custom transformer>,
})
trying it this way results in this error
> Error: There is already a parameter type with name string
I'm 99% sure we don't have that functionality. We would probably want to add a "remove parameter type" and then create parameter type would work fine.
@ec-mark What is stopping you doing
defineParameterType({
name: "marks-string",
regexp: <custom regex>,
transformer: <custom transformer>,
})
Hey @luke, it's doable, but we have dozens of steps already and actually want this transformation to apply to every passed in string. We have some environment vars set within our platform, and we'd like to provide our testers an option to run a step like
Given an HTTP request to "<http://%DOMAIN_NAME>%/api/info"
this is just a basic example, but there several places where it'd be really useful for our tests to support those kinds of strings and use the string parameter type to search for %% wildcards and swap them with the associated environment variable
Ctrl+R in any IDE to find and replace all instances of {string} for {transformed-string}
you can then also have {domain-transformed-string} and {other-transformed-string}
for example I had one called suffixed-number that took something like 2nd or 5th and returned 2 or 5
can I know how I can share datatable across the step definition with cucumber.js? for example in my When step
When('{pronoun} requests weather forecast hourly', (actor: Actor, table: DataTable) =>
actor.attemptsTo(
Log.the(table.hashes()[0].geocode),
I like the table to be accessible in my Then step
Then('{pronoun} should get the weather forecast details', async (actor: Actor) => ...
*Thread Reply:* This can be achieved by storing locally what you need with localStorage. See https://github.com/lmaccherone/node-localstorage if you use Node which looks like it’s the case for you.
So, in your first step definition, you would store each key/value pair in a local file using setItem(key, value). The name of the file is the key and the content of the file is the value (as a string).
You can then access those key/value pairs in subsequent steps with getItem(key).
And you can delete all localStorage files as part of your After(Scenario) hook.
Note that everything in localStorage is saved as a string. So you might have to use JSON.parse whenever you need to access an object, an array, a boolean etc.
*Thread Reply:* You can use the world: https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/world.md
You can assign your datatable to the wold in your first step, then use it in further steps
*Thread Reply:* It looks like you're using a screenplay pattern implementation. Nice!
If you happen to be using https://github.com/cucumber/screenplay.js/ you can do it like this: https://github.com/cucumber/screenplay.js/#sharing-data-between-steps
If not, perhaps you can implement something similar in your implementation of the actor.
hi cucumer-js folks, does anyone know how I can get cucumber-js to read scenarios from a input stream rather than a file? and if this is not possible, how can I use the cumumber-js libraries to achieve this? (I want to run scenarios that are stored remotely and fetched via an api)
*Thread Reply:* This is a timely question! I’m currently working on https://github.com/cucumber/cucumber-js/issues/1711 to add a composable API to enable things like this. Would you mind dropping a comment on there with this use case and I’ll try and make sure it’s covered?
*Thread Reply:* looks like a great addition, would this allow to easily pipe the scenarios in or does it just allow to programatically run it giving it the names of feature files?
*Thread Reply:* Sorry for late reply. There'll be a PR after this weekend. First pass might be simpler initially but the goal is to have it composable so one could e.g. pass in scenarios like you say. I'll keep you posted.
Hey, I am looking to add some screenshots which I have captured to the built in cucumber/html-formatter. I want to add them after a scenario has failed etc. so they appear nicely in the feature dropdown of each failed test on the html report. Has anyone done similar to this?
attach will give you what you need @Dillon Barker
Good afternoon! I’m a little stuck on building a custom formatter. The envelope for testCaseStarted gives me testCaseId and id . How do i get the feature or scenario name from these? getTestCaseAttempt takes a testCaseStartedId and getPickle takes a pickleIdwhen using the EventDataCollector. Am i missing something?
*Thread Reply:* @Vincent Pretre is this a case for using gherkin-utils?
*Thread Reply:* I have the same problem in the afterStep hook. I have a testStepId but i can’t see any way to get the step keyword or text using that because in the hooks i don’t have access to the EventDataCollector.
Also, I was thinking on how to better leverage Background steps. The thought occurred to me of having an AfterBackground() hook that executes after all the background steps and before the scenario specific steps. That this would allow for is having the background steps put data into the world object, and then without having a step that specifically calls for processing on that data have that process occur before starting the scenario. Thoughts?
Better would probably be conditionally memoized methods. Because then that is better controlled and would flow better.
i.e. A user called Jeff exists -> Steps create this unless they exist, in which case they do nothing.
*Thread Reply:* In the changelog: https://github.com/cucumber/cucumber-js/blob/main/CHANGELOG.md
*Thread Reply:* Thanks. I'm an idiot though, I asked this question then it immediately occurred to me to google for cucumber.js 7.3.1 changelong which gave your link as the 1st result 🙂
*Thread Reply:* ESM support is in core. Ok, I can rework my code to stop using the esm package.
*Thread Reply:* We removed it in 7.2.1 - the change in 7.2.0 did not work. So 7.3.1 has no esm support AFAIK. People are still working on it.
*Thread Reply:* I upgraded because Cucumber isn't reading it's profile or tag arguments off the command line.
*Thread Reply:* See, I have a script that reads it's own arguments off the command line to config some things, then passes off control to cucumber.
Are there any known issues with cucumber being unable to read its arguments?
*Thread Reply:* Not that I know of @Michael Morris - got an example?
*Thread Reply:* I'm ok now - The problem lay in how golang mage relays arguments. Cucumber is just fine and is the least of my worries today.
Did anyone tried tagging in cucumber js. If i have just 1 tags its works but multiple doesnt work
*Thread Reply:* Could you please give more info?
There is actually an issue that may be related: https://github.com/cucumber/cucumber-js/issues/1796#issuecomment-926318483
Do you experience the same?
*Thread Reply:* As you can see, once everything is up-to-date, I was not able to reproduce the issue.
Would you have the possibility to provide a repo with a minimal reproduction example, and all the info regarding your execution environment? Versions of cucumber-js, node, and npm, os, and the shell?
*Thread Reply:* I have create a file .env to set all my environment variables for staging. example: FARMERBASEURL=“https://farmer.stage.xx.io
*Thread Reply:* I want to set one for preprod FARMERBASEURL=“https://farmer.preprod.xx.io
*Thread Reply:* in my package.json, “test:execute”: “cucumber-js --tags=‘@test’“,
*Thread Reply:* Did you required the "dotenv" package as part of your support code?
*Thread Reply:* yes in my step defn, I add this
const dotenv = require('dotenv').config();
*Thread Reply:* then I call
ChangeApiConfig.setUrlTo(process.env.FARMER_SERVICE_BASE_URL)
*Thread Reply:* what I need to be able to switch between 2 env. one for staging one for preprod
*Thread Reply:* It seems this is not related to cucumber 🤔
What do you want to accomplish exactly?
Would you like to execute cucumber tests on both environment? Or do you want to execute the tests twice on the same environment but simulating different environments? Or something else?
*Thread Reply:* I do have the dotenv package but mostly I have ended up sourcing from different files, so it might be redundant at this point. It has nothing to do with cucumber; cucumber doesn't manage environment variables.
*Thread Reply:* ok thanks I got it resolved. using the NODE_ENV=stage cucumber.js …
Hi there, what's the default regex used to match strings? I couldn't find it in the repo
*Thread Reply:* I guess you are using cucumber expressions The repo is there: https://github.com/cucumber/cucumber-expressions
You'll find some documentation, and a sandbox to test your expressions
in my feature file I have a few test scenarios if I have one that has a bug, how can I exclude it in the cucumber-js --tags command when running my test
*Thread Reply:* here is my feature file ```@all Feature: Get farmer details In order to get farmer details As a API farmer services consumer James James wants to get farmer details based on UserID Background: Given James is at the farmer services url
Rule: Get farmer detail using a valid unique UserID
Scenario: Able to get farmer detail using userID When he get a farmer using a UserID Then he should able to get the details of the farmer
Rule: Get farmer detail using an invalid unique UserID @bug Scenario: Able to get farmer detail using userID When he get a farmer using a UserID Then he should able to get the details of the farmer```
*Thread Reply:* when running the test, I have this line in my package.json
NODE_ENV=stage cucumber-js --tags=all
*Thread Reply:* ```Rule: Unable to delete farmer from the database with invalid UserID
@test
Scenario: Unable to delete farmer from database with invalid UserID
When he delete a farmer with an invalid UserID
| invalidUserID |
| 9ebea001-89df |
| 89df |
Then he should be unable to delete the farmer
| statusCode | errorMessage |
| 400 | Path variable 9ebea001-89df is not a valid UUID |
| 400 | Path variable 89df is not a valid UUID |```
*Thread Reply:* that is the first row of the When steps will map to the first row of the Then steps, and so forth?
*Thread Reply:* I think an example table would be more appropriate: https://cucumber.io/docs/gherkin/reference/#scenario-outline
```Scenario Outline: Unable to delete farmer from database with invalid UserID
When he delete a farmer with <invalidUserId>
Then he should be unable to delete the farmer
And he shoud see <errorMessage>
Examples:
| invalidUserId | statusCode | errorMessage |
| 89df | 400 | not valid |```
Using datatables, you would have to keep the mapping between your steps by yourself.
*Thread Reply:* ok so the example I gave should still work as long as I have 2 rows for When and 2 corresponding rows for the Then steps? cos in case I have alot of parameter, I want to keep the When statement concise and brief
*Thread Reply:* It would work. The order specified in the gherkin scenarios for datatables should be the same order in your step definitions
Is https://github.com/cucumber/cucumber-js/ the best repo to learn some real Cucumber.js implementation? Just trying to learn from some examples by looking at how others use it in real project. Or there are some public repos can be used as a good example?
*Thread Reply:* You could try https://school.cucumber.io to learn the basics
*Thread Reply:* https://github.com/smartBear/git-en-boite is a repo I worked on recently that uses Cucumber JS to drive the implementation. It's an HTTP service though, not a web app.
*Thread Reply:* Feature files: https://github.com/SmartBear/git-en-boite/tree/main/doc/features
Automation code: https://github.com/SmartBear/git-en-boite/tree/main/packages/acceptance-tests/src
*Thread Reply:* You can search GitHub for projects with Gherkin in them, not sure if / how you refine that just to TypeScript/JavaScript projects.
https://github.com/search?l=&q=language%3AGherkin&type=repositories
*Thread Reply:* @Aslak Hellesøy I have read a lot docs and tutorials(include https://school.cucumber.io) also used in my project. But feel most of the tutorials are too simple, like a hello world . When I start use it in a big scale project, I got too many questions.
*Thread Reply:* Ask the questions @Tim Yao! Then come back and answer other peoples' when they have them later!
*Thread Reply:* Thanks @matt-SmartBear for the sharing. The search language is a good idea, I will use it to explore other repos. 😁
*Thread Reply:* Some opensource has a awesome … repo, list all projects used the product.
*Thread Reply:* for example https://github.com/vuejs/awesome-vue
*Thread Reply:* Yeah that would be good. It's always been quite rare finding open source projects that use Cucumber - so many are proprietary and in-house, but they are out there
*Thread Reply:* I guess maybe there is already stuff like this in the docs, probably hideously out of date...
*Thread Reply:* https://github.com/virajkulkarni14/Awesome-Cucumber
*Thread Reply:* If you want me to create a repo under the cucumber org for this, lmk
*Thread Reply:* For me, I think cucumber has a nice documentation site already, so mainly is for other resources.
*Thread Reply:* I also try to find time read your blog https://cucumber.io/blog/. It’s good place to learn as well.
*Thread Reply:* Please let me know when you got the repo set up 🙂 cheers
Hi all. Can anyone recommend a github project that uses Javascript + selenium + cucumber extensively? I am trying to go beyond the tutorials offered in books / websites and more examples of real world usage
*Thread Reply:* Let's see if this trawls anything up https://twitter.com/mattwynne/status/1452515301396922368
Hi everyone,
Has anyone come across CancellationError in any of the scenarios? I have a total of 26 scenarios, but for some reason, I received CancellationError on my 2nd scenario, and all the remaining scenarios weren't executed at all.
*Thread Reply:* That’s not an error thrown by Cucumber, @Cem.
CancellationError: There was an uncaught error in the control flow: StaleElementReferenceError: stale element reference: element is not attached to the page document
(Session info: chrome=93.0.4577.63)
*Thread Reply:* That's a WebDriver error.
https://developer.mozilla.org/en-US/docs/Web/WebDriver/Errors/StaleElementReference
It happens when you have a handle to an element, but by the time you run the code to interact with it, it's been deleted from the page.
Hmm, apparently calling setWorldConstructor more than once doesn't work.
*Thread Reply:* It sounds plausible that you can't call it more than once. What's the error that you see?
In an afterScenario, what variable do I use to see if the test passed? I am trying to integrate with Browserstack and they have the following snippet for webdriverIO (to tell browserstack the test passed or failed); however this is not with cucumber (I'm using webdriverIO with cucumber 🥒 ).
afterTest: function (test, context, { error, result, duration, passed, retries }) {
if(passed) {
browser.executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": ""}}');
} else {
browser.executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": ""}}');
}
}
*Thread Reply:* I will try "if(success)" https://cucumber.io/docs/cucumber/api/
As such you need to code your own thing. I wrote a singleton class that by default had the value as passed, and then if any test failed it updated the value to failed.
*Thread Reply:* not sure what it's called in JS. It occurs after each scenario.
*Thread Reply:* Ok. But what I need to know is how do I interrogate the state?
Cucumber adds green checkmarks to steps that passed. Red x to the ones that failed, etc.
So there must be some way to access the pass / failed state?
*Thread Reply:* Ok maybe this will help https://cucumber.io/docs/guides/browser-automation/#screenshot-on-failure
*Thread Reply:* I tried with
if (scenario.isFailed()) {
however I get this error:
[0-0] 2021-10-29T16:58:23.360Z ERROR @wdio/utils:shim: TypeError: scenario.isFailed is not a function
*Thread Reply:* afterScenario: function (scenario, world) {
if(scenario.isFailed()) {
...
}
*Thread Reply:* Ok I realize it might be more WebdriverIO that I need to deal with https://webdriver.io/docs/configurationfile/
Looks like there is an optional "result" param; will try that
afterScenario: function (world, result) {
Hi everyone,
On cucumber 6 I was using HookScenarioResult as a parameter for my after function to retrieve scenario names. What do i need to use on cucumber 7.3.1?
scenario name is no longer present in the pickle. as such you cannot access it. Whilst this has been a bit of friction, it's likely to not go away any time soon
See here for more info / discussion (Different flavour, but same principle)
https://github.com/cucumber/cucumber-ruby/issues/1432
The JS variety is here: https://github.com/cucumber/cucumber-js/issues/1740
@matt-SmartBear We are using lambdatest for automation. I would like to assign my test scenario names to lambdatest name to differentiate which test failed which test passed on lambdatest dashboard
Well it looks from https://github.com/cucumber/cucumber-js/pull/1775 like there might be some light at the end of the tunnel.
Are you able to try the v8 release candidate? https://github.com/cucumber/cucumber-js/blob/main/CHANGELOG.md#800-rc1---2021-10-19
Hello everyone! I have one question about the why cucumber.js not included Gherkin keywords AND, BUT ?
@Eduardo Castro none of the Cucumber implementations do. An And or a But is just syntactic sugar for not repeating Given, When or Then.
Logically, and And or But step is one of Given, When or Then.
*Thread Reply:* ```Feature: Button Event Handling In order to validate Button event handling As a QA tester Jan Jan wants to see how the ahua button event behave
Background:
Given Jan is at the app
Scenario Outline: Ahua Button Event Change title When he want to trigger button event to change the button title | event | | onPress | Then he is able to see the button title changed "<title>" Examples: | title | | buttonTitle |```
*Thread Reply:* You can use both scenario outline and datatable in the same scenario.
But they won't be automatically "combined" as you would like as I presume from your sample. You would have to program it by yourself.
However, in your case, why couldn't your writte the following?
```Feature: Button Event Handling In order to validate Button event handling As a QA tester Jan Jan wants to see how the ahua button event behave
Background:
Given Jan is at the app
Scenario Outline: Ahua Button Event Change title When he want to trigger button <event> to change the button title Then he is able to see the button title changed "<title>" Examples: | event | title | | onPress | buttonTitle |```
Hello. Is there an easy way to get the examples for current test run in before hook? I was trying to parse if from the testCase.picke.steps , but it seems that for some scenarios they are not there 🤷 .
*Thread Reply:* A test case is the result of a scenario being transformed as a test. A scenario with N examples will result in N test cases. The test case is an example.
The Before hook is executed before each test case, not before each scenario.
Thus the before hook has no access to other examples of the scenario than the one it has been calling for.
Does that help?
*Thread Reply:* @Aurélien Reeves thanks for the explanation. Yeah, I get that, but I find it a bit tricky to get the "examples" for current test case.
Currently exploring the astNodeIds to match them with ids in gherkinDocument
*Thread Reply:* What do you call "examples" for the current test case?
*Thread Reply:* There are no "examples" for a test case: a test case results from a single example of the scenario outline
*Thread Reply:* Ok, I am trying to get the "examples" inputs (the table data) for each test case as I have a logger and need to distinguish the different test runs of the same scenario outline.
*Thread Reply:* made it work like this: ```const parseExamples = (testCase: ITestCaseHookParameter) => { const examplesMap = new Map() const scenarioId = testCase.pickle.astNodeIds[0] const exampleId = testCase.pickle.astNodeIds[1] const scenario = testCase.gherkinDocument.feature.children.find((child) => child.scenario.id === scenarioId) const cells = scenario.scenario.examples[0].tableHeader.cells const values = scenario.scenario.examples[0].tableBody.find((body) => body.id === exampleId)
cells.forEach((cell, index) => {
examplesSet.set(cell.value, values.cells[index].value)
})
return examplesMap
}``
but not sure if the order ofastNodeIds` is guaranteed and if there could be more ids in some cases?
*Thread Reply:* I see. You want the row in the table which has been used to generate the test case? Not all the rows?
I guess your snippet should work well indeed
*Thread Reply:* Yes, thats it, sorry for not using the exact terms 😉 It works fine it seems , it was just missing a couple of optional chaining to avoid failures for non-scenario outlines.
*Thread Reply:* @matt-SmartBear it's just not super user friendly, took me a while to comprehend it.
*Thread Reply:* In Ruby, I think we wrap this raw test case object with a facade that has some more helpful stuff on it. We could consider doing that for JS too.
*Thread Reply:* @Luděk Nový what would the API have looked like here, in an ideal world? Could you sketch out some code?
*Thread Reply:* Thats a tough question, but for the above described use case, ideally it would not be necessary to iterate so many times, eg, exposing the example values in pickle object or something. and I did not find any docs for it, eg whether the order of astNodeIds is guaranteed, of there could be more then 2 items in the array and so on.
*Thread Reply:* So something like this perhaps?
Before((scenario: RunningScenario) => {
console.log(scenario.exampleRow?.cells)
})
*Thread Reply:* yes! that would be much easier to use than the current api 🙂
*Thread Reply:* OK I raised an issue so we can start the process of making this happen: https://github.com/cucumber/cucumber-js/issues/1851
*Thread Reply:* @Luděk Nový if you'd be interested in working on a contribution for it I'd be happy to support you with it.
*Thread Reply:* It should be a fairly straightforward change, and super useful
So, in 8.0.0 how do you activate esm modules? I don't see anything obvious. I'm trying to get away from using the npm esm package as a shim to convince it to work.
*Thread Reply:* This works but it's ugly: "node -r esm node_modules/@cucumber/cucumber/bin/cucumber-js"
*Thread Reply:* And I'm not sure it will work with parallel mode.
K, got cucumber.js to work as a module file without rewriting cucumber.
export default "";
export const altProfile1 = `args as normal here`;
export const altProfile2 = `args as normal here`;
That also passes lint rules (eslint doesn't like there not being a default). This isn't in the current documentation, how would I go about adding it?
@Michael Morris there is actually nothing to do to activate esm modules. It should just work out of the box within a project which uses ESM.
I've just pushed an example here: https://github.com/aurelien-reeves/cucumber-js-esm-example The project is a node module using ESM. The support code also uses ESM without any specific configuration. Please just note the use of a common-js configuration file: this is a current limitation of cucumber-js as explained at the bottom of the following document: https://github.com/cucumber/cucumber-js/blob/main/docs/esm.md
Ok, I didn't need to do a cucumber .cjs file. As pointed above the file can be done in module format and it will work. There are still problems when running cucumber within a module though. I blame the node team for this - frankly the node rollout of es6 support is attrocious.
*Thread Reply:* Actually your cucumber.js file is working as a module because of your hack.
Your hack load cucumber itself as a module, which it is not. I would encourage you to try removing your hack and using a .cjs file for the configuration. Everything else should work properly using esm imports / exports.
*Thread Reply:* They don't though. I tried that first - path of least resistance and all.
*Thread Reply:* I'm in an odd situation. I have a client extending library of cucumber that adds API services emulation for tests that is imported as a module by the actual projects that have the critical system tests.
*Thread Reply:* The reason for this structure is there are multiple projects that need to import this library.
*Thread Reply:* Those projects exist as esm modules for... reasons. (Testing did not exist at the beginning of the project and I'm struggling to bring it in).
*Thread Reply:* I could extract my hack out to a tiny project - cucumber-esm. The ESM package smooths over a lot of node's mistakes with ES6.
*Thread Reply:* I am not sure to get it actually 😓
Do you think you could setup a minimal reproducible example in a dedicated new repository?
That way we could have a deeper look inside the issue you are facing, that may help us improving esm support
*Thread Reply:* Amazing! Thanks!
And no worries for the delay :)
I'll keep using my ugly script line hack, everything else works great.
Here's a documentation pull request for what I suggest. https://github.com/cucumber/cucumber-js/compare/main...michaelm-rsi:patch-1
*Thread Reply:* Well, this is too specific, and requires your script hack to work. So we won't be able to merge this as-is, sorry.
I'm curious as to how the new runCucumber API will accomplish this code block (Thread)
*Thread Reply:* ```async function runCucumberTest(args, expectError = false) { return new Promise((resolve) => { const allArgs = ["run", "self", "--", "--site", webserverPath].concat(args); const runner = spawn( /^win/.test(process.platform) ? "npm.cmd" : "npm", allArgs, { // Uncomment next line to pass inner test's output to console. Do this // only when debugging this script. // stdio: "inherit", env: { ...process.env }, } );
runner.on("exit", (code) => {
if (expectError && code) {
resolve("pass");
} else if (expectError && !code) {
throw new Error("Expected test to fail and it did not");
} else if (!expectError && code) {
throw new Error("Test failed unexpectedly");
} else if (!expectError && !code) {
resolve("pass");
} else {
throw new Error("This code should be unreachable");
}
});
}); }```
*Thread Reply:* To be clear, the code above works fine - it's my current work around on the lack of a true runner setup.
*Thread Reply:* My world object has an AfterAll hook that scans the browser console for errors. If it finds any, it fails the test immediately.
*Thread Reply:* I need to test that hook and this is what I came up with to insure it would fail on cue.
Any tutorials on using cucumber logging? I'd like to use it, but I need to see it's output. Currently I'm using npm's logger.
*Thread Reply:* What do you mean by "cucumber logging"?
Did you noticed the following: https://github.com/cucumber/cucumber-js/blob/f37edaadbefea557d87ef5f19bc301a277ac4264/docs/support_files/attachments.md#logging?
I've tried with and without the prettier format and the log messages aren't showing. What's the point of a logger if you can't see it's output?
Are the available format-options for any formatter documented anywhere?? SMH
*Thread Reply:* It relies on the formatters to document their options.
For built-in formatters, the option that is well documented is the one to disable colors for outputs to the terminal.
There is also the customization of snippets which uses those options. This is documented here: https://github.com/cucumber/cucumber-js/blob/c3a33139366a205d12e4e707eead75ae2ae1d2d8/docs/snippets.md
I'd like to generate the following feature in code rather than have it in my features directory.
Feature:
@dev
Scenario: Development and demo preset
Given Development
The step definition configures the mock server and cookies, then the developer can manually work with the data while developing. It isn't in and of itself a feature.
(If anyone is wondering why this even works, I have a global after step that pauses the runner between runs when the system is in debug mode - waiting for input from the command line. So they can run this "feature" and the system will stay paused after parsing the given indefinitely while they play with the browser and the data they created.)
*Thread Reply:* You can create a cucumber.js file in the root folder of your project, next to your package.json file
*Thread Reply:* When I tried that it continued to print the message. Is there another step included?
*Thread Reply:* That is weird Can you paste the content of your cucumber.js file, and the script you use to run your tests ?
*Thread Reply:* I had a typo in cucumber -_- I’m sorry, that did work after all
*Thread Reply:* No worries! I am glad you made it work after all 😁
We use Cypress and Cypress Cucumber pre-processor. Just wonder is it possible to see (programmatically) scenario tags inside a steps of that scenario?
*Thread Reply:* May I ask: what are you trying to achieve?
I am not sure we can know tags on a scenario from within a step directly. You may have to implement a specific world to do that.
I don't know if that may help, but you may have access to those tags from beforeStep and afterStep hooks.
Documentation for the "world": https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/world.md
Documentation for hooks: https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/hooks.md#beforestep--afterstep
More documentation in the api reference: https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/api_reference.md#afterstepoptions-fn
*Thread Reply:* Best way (Using my cucumber analogy), is you create an info class (in js probably an object), that you inject at world creation time (So from your hooks), then access this object inside your step invocation
*Thread Reply:* [Sorry, don’t have time to look at the previous comment’s links.] We definitely do it in Before(), which comes just before the Scenario runs. Here’s some sample code:
Before(async (scenario) => {
let scenario_name = scenario.pickle.name;
}
Hello, I was wondering if you could help me with this. I'm clone the repo hps-cucumber-javascript and notice that the tests can be seen only in the extern feature file. Can the structure be changed ? I was wondering if we could have the project structure like this : src/app and src/test, src/test containing both features and glue.
*Thread Reply:* Hi 🙂
I guess you can have the structure as you want:
• move the app itself from src to src/app • edit ./cucumber-js.conf output_directory from ./features to ./src/test • update ./features/actionwords.js to properly require the app from ./src/app rather than ./src • update the call to cucumber-js to let him know where to find features and step definitions Beside that, may I ask:
• why are you using hps-cucumber-javascript? • did you noticed that it is set-up with a pretty old version of cucumber? I would encourage to update your fork to work with latest version of cucumber-js. That may certainly require a lot of fix and customization.
*Thread Reply:* Thank you for your reply! 🙂 I'm new with cucumber-js, I saw that template and I'm trying to see how it works.
*Thread Reply:* Are you also a user of cucumber studio or hiptest publisher?
Does someone know how I can capture the text cucumber outputs into the command prompt console at various stages? For example, the progress output, the error messages, and the final success/failure logs. I’m making a report and I’d like to include that output in the report.
*Thread Reply:* If you want to grab those pieces separately you'd need to write your own custom formatter.
*Thread Reply:* There's an example of that here: https://github.com/cucumber/cucumber-js/blob/main/features/custom_formatter.feature
*Thread Reply:* If you have a look at the source for the ProgressFormatter (https://github.com/cucumber/cucumber-js/blob/main/features/custom_formatter.feature) you should get some clues.
*Thread Reply:* Thanks, we’ll check it out and give it a shot. Seems more needs to go into it than we thought, so it may take us a little while, but thanks for the pointers 👍
Does any one has cucumber.js integrated with a test case management system? Any of them has easy to use integration? zephyr? xray? Our team is looking at TesRail at the moment and I worried it won’t be a good option for cucumber to work with.
*Thread Reply:* Hello Tim,
The zephyr products have integration with Cucumber.
Zephyr, among other, are Smartbear products. And as you may know, Cucumber is supported by Smartbear too.
We have dedicated teams dedicated on integrating BDD and Cucumber into Zephyr. That team is really close to us at Cucumber Open.
*Thread Reply:* Yes, I know, as they are all in Smartbear, I assume they can integrated better than others. Is there any code example or demo video for cucumber-js Zephyr integration? I only see one for Java https://github.com/SmartBear/zephyr-scale-cucumber-integration-example
*Thread Reply:* At first, which Zephyr are you talking about? Zephyr scale, squad or enterprise? Those are 3 different products actually.
Then I'll be able to look for someone to give you more accurate help 🙂
*Thread Reply:* Zephyr scale I think. But sad Zephyr is not even on our QA’s list 😅
*Thread Reply:* Hi Tim! So both Zephyr Scale and Squad propose an integration for cucumber. Both rely on a call to an api endpoint to upload your results. In scale it is here: https://support.smartbear.com/zephyr-scale-cloud/api-docs/#tag/Automations. You either use the tag as described in the example you mentioned, or Scale will create your test cases on the fly if they do not exist yet in the library. Squad behaves the same way: https://support.smartbear.com/zephyr-squad-cloud/docs/test-automation/index.html even tho it is a bit more complex to create the task.
*Thread Reply:* In scale, your scenario results will look like this: https://app.getbeamer.com/zephyrscale/en/better-visualization-of-your-cucumber-results
*Thread Reply:* Thanks @David Lechevalier, that’s really helpful. For API, is there an integration plugin/addon for cucumber-js to use directly? Or I need to write by my own.
*Thread Reply:* No direct integration. You need to to somethnig like this:
curl -X POST <https://api.zephyrscale.smartbear.com/v2/automations/executions/cucumber>\?projectKey\=${PROJECT_KEY}\&autoCreateTestCases\=true \
-H "Authorization: Bearer ${ZSCALE_TOKEN}" \
-F "file=@results.zip"
Woith the project key being the key of your jira project and the ZScale token being the authentication token you get from Zephyr Scale. The zip files include the results of your execution as json files
*Thread Reply:* Got it. Thanks. I will take some time to have a look at them. 👍
Before({tags: "!@foo"}, function () {
// This hook will be executed before scenarios tagged with @foo
});
Exclude tag @foo
*Thread Reply:* Before({tags: "not @foo"}, function () {
// This hook will be executed before scenarios tagged with @foo
});
*Thread Reply:* I don't think the comment says what you want it to say
*Thread Reply:* @Tim Yao thanks that's it.....
I keep getting ✗ Error: function timed out, ensure the promise resolves within 5000 milliseconds in headless mode. where can I adjust this timeout? I am using the serenityjs, webdriverio and cucumber framework https://github.com/serenity-js/serenity-js-cucumber-webdriverio-template
*Thread Reply:* ```Caused by: Error: Wait timed out after 5s
[test:stage:execute] at xx/node_modules/webdriverio/build/commands/browser/waitUntil.js:66:23
[test:stage:execute] at async Browser.wrapCommandFn (xxx/node_modules/@wdio/utils/build/shim.js:131:29)
[test:stage:execute] at async World.<anonymous> (/xxx/src/step-definitions/createCredential.steps.ts:```
*Thread Reply:* seems like a webdriver thing. I’m not familiar with webdriver, but I use Cypress and there is a custom config you can pass to extend the wait time
*Thread Reply:* yeah same in webdriver https://webdriver.io/docs/api/browser/waitUntil
I’m using a node script to run my cucumber test file:
"cucumber_base": "./node_modules/.bin/cucumber-js --require ./lib/index.js",
I’d like to take ./node_modules/.bin/cucumber-js out and just require it in one of the files. Is that actually possible with an executable like that?
*Thread Reply:* Hi @plocket I guess you want to run Cucumber-js in a programmatic way. I found an open issue https://github.com/cucumber/cucumber-js/issues/1711 and looks like they are working on it for v8 but no public API yet.
*Thread Reply:* @plocket Here is an example how Nightwatch.js v2 uses cucumber cli in their js file https://github.com/nightwatchjs/nightwatch/blob/main/lib/runner/test-runners/cucumber.js Not sure if it’s a best practice. But maybe can help you, just copy it.
Hello, i was wondering if you could help me. I'm facing a problem while trying to complete a step "Checking if the email and password fields are in the default state after refreshing page". This is how i'm checking if the fields are containing any text:
this.driver.wait(until.elementLocated(this.elements.emailPlaceHolder));
this.driver.findElements(this.elements.emailPlaceHolder)
.then(function() {
expect(this.elements.emailPlaceHolder.getAttribute("value")).to.equal('');
});
But I'm getting this error: "TypeError: Cannot read property 'wait' of undefined", even if I'm using directly the by.css, not a variable, in the wait function.
*Thread Reply:* From the small amount of information this is an error from the driver, not the selector.
*Thread Reply:* I tried to add a new declaration for driver :
his.driver = new selenium.Builder().withCapabilities({
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true,
chromeOptions: {
args: ['start-maximized', 'disable-extensions']
},
// path: chromedriver.path
}).build();
but it throws the same error. Is there a better way initialize the driver? In the other steps the wait and findElements work with no initialization for the driver
*Thread Reply:* What happens if you console.log(this.driver) right before the original code?
*Thread Reply:* Silly question, but are you using this inside of an arrow function eg: () => {/****code here****/}
*Thread Reply:* I'm getting an undefined for the driver with console.log
*Thread Reply:* This is the function : checkEmptyEmailAndPassword: function () {
driver.wait(until.elementLocated(this.elements.emailPlaceHolder));
driver.findElements(this.elements.emailPlaceHolder)
.then(function() {
expect(this.elements.emailPlaceHolder.getAttribute("value")).to.equal('');
next();
});
}
*Thread Reply:* I’m not sure. Seems like a Selenium issue though. If you’re using the driver.wait function elsewhere I’d compare those calls to this one.
*Thread Reply:* I’ve used selenium in the past, and I recommend cypress because their docs are easier to read and better maintained.
*Thread Reply:* in some places i've noticed that findElement() sents an object with the promise instead of the webElement. Could it be an issue with the driver ?
*Thread Reply:* But in their case, they are declaring the findElement then awaiting the response. You are just having an issue with driver not being defined
*Thread Reply:* Thank you for your reply! I will try what you suggested
*Thread Reply:* @Joe A try { default: “--publish-quiet --format html:path/to/report.html” }
*Thread Reply:* Also see https://github.com/cucumber/cucumber-js/blob/main/docs/formatters.md
Hello, I've seen here https://cucumber.io/docs/cucumber/mocking-and-stubbing-with-cucumber/ that it's possible to mock a server with cucumber-js. I was wondering if you could tell me which framework would be better?
*Thread Reply:* As explained in the doc, it really depends on your actual stack and needs.
What do you need to achieve? Which kind of server do you need to mock?
*Thread Reply:* I want to test the front end of an application, and I need to mock responses from the Backend. For example the case for reset password, I need to mock the token because otherwise it would be something random I couldn't implement some steps without knowing its value.
*Thread Reply:* I think I would implement a fake backend myself as this is fairly simple to build a http server using node-js.
Do you need to also spy the fake server? Or mocking it would be fine?
*Thread Reply:* if you're using nodejs for mocking the server do you need to run the server separatly ? Or can i mock the server in the in steps already implemented and run everything with only one command for the cucumber tests?
*Thread Reply:* You can basically do whatever you want actually
How do you execute your tests? Do you use npm scripts?
*Thread Reply:* I'm running them using this command : "node ./node_modules/selenium-cucumber-js/index.js -s ./step-definitions"
*Thread Reply:* I would recommend using npm scripts. To do so, in your package.json, add the following script:
"scripts": {
"test": "npm run test:cucumber",
"test:cucumber": "node ./node_modules/selenium-cucumber-js/index.js -s ./step-definitions"
}
Then to execute your tests, you would just have to run the following command: npm test.
Regarding your server, I would to managing it using hooks
You could start it using the beforeAll hook, and make sure to stop it in an afterAll hook.
You could also manage it using tags: you could have a tag which indicate that a scenario requires the server, then using Before and After hooks to start and stop the server per scenario depending their tags
Hi! I'm facing a problem with the chromedriver and I was wondering if you could help me. I deleted the node_modules due to a previous error. But after installing the chromedriver and everything again I have this error
This version of ChromeDriver only supports Chrome version 86
Current browser version is 97
I've checked the version of the chromedriver with chromeDriver -v and it's 97, I also replaced everything in the package.json and package-lock.json to be 97 version. The error still shows. The commands that I used are: npm install selenium-cucumber-js --save-dev and npm install chromedriver --chromedriver_version=LATEST
*Thread Reply:* You may have another instance of Chrome driver installed
What is the result of which chromedriver ?
*Thread Reply:* Should it be installed in another way or with another command then?
*Thread Reply:* I've also tried to install chromedriver97 version and move it to usr/local/bin but it still says chromedrive not found
*Thread Reply:* Did you miss the final r or is it copy/paste issue?
*Thread Reply:* chromedriver -v still displays the wrong version number?
Make sure to also use the proper case for chromedriver. Don't know if it is chromeDriver or chromedriver
*Thread Reply:* i missed the r, the return is : /Users/manuelamag/.nvm/versions/node/v16.7.0/bin/chromedriver
*Thread Reply:* It seems you previously installed it globally (using npm i -g)
Try updating that one, or removing it to make sure using the local one
*Thread Reply:* after npm uninstall chromedriver it should use the local one? I tried but I got the same error
*Thread Reply:* no. Actually, npm uninstall chromedriver may have uninstalled the local one
Try to:
• npm uninstall -g chromecriver to uninstall your global chromedriver
• npm uninstall chromedriver to uninstall the local chromedriver if it is still there
• rm -rf node_modules to remove the node modules folder
• rm -f package-lock.json to remove the npm lock file
• npm install to reinstall all the packages
• npm install --save-dev chromedriver to reinstall chromedriver for your project
Disclaimer: uninstalling chromedriver globally may break other projects on your computer. If you want to keep the global one, make sure to update it npm update -g chromedriver but do not uninstall it. Using global packages is discouraged, but if you have some dependencies on it, you may keep it
*Thread Reply:* I tried the steps, but still shows the same error. I've removed the global driver
*Thread Reply:* Could you paste the "devDependencies" section of your package.json?
What is the result of which chromedriver ? chromedriver -v ? npx chromedriver -v?
Which error do you have? The following one?
This version of ChromeDriver only supports Chrome version 86
Current browser version is 97
*Thread Reply:* It seems that selenium-cucumber-jsactually depends on chromedriver v86: https://github.com/john-doherty/selenium-cucumber-js/blob/master/package.json#L43
If you want to still use that package, you may have to use chrome 86.
It seems selenium-cucumber-jsis not that maintained: https://github.com/john-doherty/selenium-cucumber-js/commits/master
You may consider to avoid using it and do the automation by yourself 😓
*Thread Reply:* I see the problem now, thanks! Could you perhaps tell me what would be a better package or maybe an easier to follow example ? I'm new with cucumber-js.
*Thread Reply:* Well, maybe puppeteer with puppeteer-cucumber-js? https://github.com/john-doherty/selenium-cucumber-js
*Thread Reply:* I have another question, I see that puppeteer works with chromium, I search online but I did not find anything about the difference between chrome and chromium when it comes to testing. Do you know if there is a big difference between them?
*Thread Reply:* No difference between them for testing, don't worry 🙂
Are there any scenarios that integrated cucumber js with service now to create problem records?
*Thread Reply:* There's certainly nothing built into Cucumber, but it's pretty straightforward to use a REST API. It looks like ServiceNow has one:
https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/
*Thread Reply:* SuperAgent is a nice library for making REST calls: https://www.npmjs.com/package/superagent
*Thread Reply:* Or you can use node-fetch: https://www.npmjs.com/package/node-fetch
After @Josh Houlker asked for a typescript example the other day, I created a new repo of cucumber-js examples, here. It's a bit empty at the moment!
What are some other common setups you'd like to see examples for? A React app, for example, or Angular-JS? Using frameworks like Selenium, Cypress or Puppeteer? Please let me know!
*Thread Reply:* I get clients using React, Angular, Promises. I’ve managed to grok Promises enough to build a Jasmine example, long ago. But I don’t know enough about React or Angular to sling code with any authority. So, in brief: ALL OF THE ABOVE! 😂
*Thread Reply:* very nice. if I find the time I would like to add a 'fullstack' example with node backend and react frontend tested together in cucumber
*Thread Reply:* it would also be very helpful to have examples of mocking and assertions with libraries like chai or jest
*Thread Reply:* I’d really love to see examples of customizing the formatter. Something I’ve wanted to play around with in the past but don’t even know where to start
*Thread Reply:* hey @matt-SmartBear how do I contribute an example?
*Thread Reply:* 👋:skintone2: hi Matt.
Good question, we should probably document that!
I'm hoping you can clone the https://github.com/cucumber-examples/cucumber-js-examples repo, add a new folder in examples with your example, link to it from the README, then send us a pull request.
Does that make sense?
*Thread Reply:* makes perfect sense! but I had a permission denied error when I tried to push my branch ... what am I doing wrong? it should be from a fork?
*Thread Reply:* here is the example I've committed to a separate repo for now 😉 https://github.com/explosivose/cucumber-example-ts-node-react
*Thread Reply:* Did you push to a fork of the repo, or had you just cloned the one in the cucumber-examples org?
*Thread Reply:* If you try to push to the one in the cucumber-examples org, you'll get a permission denied as you're not a member of that org (yet)
*Thread Reply:* https://docs.github.com/en/get-started/quickstart/fork-a-repo
*Thread Reply:* That should let you push (to your fork) then you can make a pull request from there.
*Thread Reply:* Let me know if that doesn't make sense! Sorry there's not a contributor guide yet!
Dear CucumberJs people, at our company we are trying to setup a new test-system for our existing app using the setup CucumberJs, Typescript and Playwright. For our tests we would like to have access to the code of our own app (Angular + Typescript), for example to use some helper classes to do api calls.
Now, I have a hard time to import our app code in the tests. The problem is that we have some complited circular dependencies in our app code. For our app we use tsconfig.json -> module: es2020 with which we can manage the circular dependencies well. We use a index.ts file where we define the "correct" order to import the files. But, unfortunately CucumberJs does not support Typescript + es2020 Module, but needs us to use CommonJS (https://github.com/cucumber/cucumber-js/blob/main/docs/esm.md). But, I have a really hard time getting our circular dependencies to work using CommonJS as the CommonJs way of importing files is different.
I would appreciate any suggestion as I am stuck with this problem. Is there a chance that CucumberJs supports es2020 + Typescript in near future?
*Thread Reply:* Do you think it would be possible to share a public repo with a minimal reproducible example?
*Thread Reply:* Take a look at screenplay. https://github.com/cucumber/screenplay.js/
*Thread Reply:* I ran across it while looking at Playwright as a possible upgrade from Puppeteer which is what I'm currently using. I haven't had a chance to look at it in depth but it looks promising.
*Thread Reply:* Thank you for your responses. I decided to give up the attemp to integrate our app code into the cucumber tests because I encountared also other problems.
My original idea was to perhaps also write our unit/integration tests with cucumber where I would need direct access to the app code. Is this something you would recommend or would you say generally cucumber should be used only for end-to-end tests?
*Thread Reply:* I use Cucumber to test the javascript layer of a web application without working with it's actual API, which is quite complex. Using a concoction of Node, Express and Faker I generate test data, and I use Puppeteer's request interrupt feature to redirect API calls to this mock server.
That's why screenplay intrigues me if I understand it's readme correctly. It has the ability to abstract away this mocking from the main test so that it can run in both end2end and functional modes.
*Thread Reply:* ** https://cucumber.io/blog/the-worlds-most-misunderstood-collaboration-tool
*Thread Reply:* Not sure if you posted this link here or it was a bot, but found that article really good to better understand the intention of cucumber: https://cucumber.io/blog/the-worlds-most-misunderstood-collaboration-tool
Hello, I have a problem and I was wondering if you could help me. I running 2 different scenarios: one for successfully sending an email to the user and one to go back to a previous page. If I run them separately they pass, but if I'm running them together the second one fails saying in the first step that it cannot find the element (a modal that says the email was sent successfully) from the previous scenario's last step. I tried to add a setTimeout to the last step from the first scenario, but I still get the same error. Same thing happens if a scenario fails, the next one's first step will fail as well
*Thread Reply:* async/await is your friend if you aren't already using it
*Thread Reply:* The first scenario
``` Given('I land on Forgot password Page', async function () { await driver.get("https://dev.io/forgot-password"); }); When('I click on Submit', async function () { var submitButton = By.css('body > app-root > app-forgot-password > div > div > div > div:nth-child(2) > div.login.center > form > div:nth-child(2) > div > app-button > div > div > button'); var forgotEmail = By.css('body > app-root > app-forgot-password > div > div > div > div:nth-child(2) > div.login.center > form > div.form-group.mt-3.col-8.input-position > app-input > div > div > input');
await driver.findElement(forgotEmail).sendKeys("email"); await driver.wait(until.elementsLocated(submitButton), 10000); await driver.findElement(submitButton).click(); }); Then('I see the Success message', async function () { var error = By.css("#myModal > div > div > div > div.flex-item-content > div.modal-body"); var value = "An email has been sent to you with a link to reset your password."; await driver.wait(until.elementLocated(error, 10000)); driver.findElement(error) .then(function() { driver.findElement(error).getText() .then(function (state) { value = state; expect(value).to.equal(state); } ); });
// setTimeout(function() {
// }, 3000);
});
Second scenario:
Given('I land on Forgot password Page', async function () {
await driver.get("https://dev.io/forgot-password");
});
When('I click Back to login', async function () {
var backButton = By.css("body > app-root > app-forgot-password > div > div > div > div:nth-child(2) > div.login.center > form > p");
await driver.wait(until.elementLocated(backButton, 10000));
driver.findElement(backButton)
.then(function() {
driver.findElement(backButton).click();
}
);
await driver.getCurrentUrl()
.then( function(currentUrl){
expect("https://dev.io/login").to.equal(currentUrl);
});
});
Then('I am directed to the Login Page', async function () {
var backToLoginButton = By.css("body > app-root > app-forgot-password > div > div > div > div:nth-child(2) > div.login.center > form > p");
await driver.wait(until.elementsLocated(backToLoginButton), 10000);
await driver.findElement(backToLoginButton).click();
});```
*Thread Reply:* I recommend trying to simplify your selectors a bit. You should be able to remove some ">" and find descendants (with just a space) instead of direct descendants (here's a random resource: https://www.freecodecamp.org/news/css-selectors-cheat-sheet/). This will make your code cleaner.
It sounds like you are possibly running into some state issues. You could try: https://webdriver.io/docs/api/browser/reloadSession/ (if using webdriverIO)
Finally, this is not really a cucumber question, more of selenium/browser question, and you may find better support elsewhere (webdriverIO has a gitter chat, for example).
I think I’ve misunderstood something about npm, but maybe it has to do with cucumber. I did npm install --save @cucumber/cucumber and the package.json shows a pre release version: "@cucumber/cucumber": "^8.0.0-rc.2". Does anyone know if I’ve done something wrong?
When I edit to ^8.0.0 and run npm install I get “No matching version found for @cucumber/cucumber@^8.0.0”
They tagged their rc as "latest" either on purpose or otherwise. If you want an earlier version you'll need to specify one of the 7. packages
*Thread Reply:* I don't think you “tag as latest” in npm do you? That's a docker thing AFAIK
*Thread Reply:* It's unfortunate that when you install without specifying a version you get the RC. It'd be better if you got the latest stable instead.
*Thread Reply:* Oh I was wrong https://docs.npmjs.com/cli/v8/commands/npm-publish
*Thread Reply:* I’m not sure about npm and “latest”. I don’t publish a lot, sorry. I did think it was not supposed to pull in pre-releases.
*Thread Reply:* This default behavior has gotten me in the past as a publisher so I assumed it wasn't on purpose, but didn't want to jump to conclusions in a public forum! Thanks for weighing in David
*Thread Reply:* in the meantime i guess publishing a new patch version from the 7.x branch would make that latest and mitigate in the short term
*Thread Reply:* Could we use npm-dist-tag to tidy up? https://docs.npmjs.com/cli/v8/commands/npm-dist-tag
*Thread Reply:* Okay that’s done, so now our tags are:
latest: 7.3.2
next: 8.0.0-rc.2
(Given the convention of tagging betas and rcs as next in JS land)
*Thread Reply:* @matt-SmartBear watch out for a PR that updates our npm release action
*Thread Reply:* https://github.com/cucumber/action-publish-npm/pull/1
*Thread Reply:* Nice one @David Goss! I've released v1.1.0 of the action-publish-npm GitHub action with this new input in it. How will we use it?
*Thread Reply:* just working that up in cucumber-js now, hold my beer
*Thread Reply:* behold https://github.com/cucumber/cucumber-js/pull/1905
~I’m moving from 6.x.x to the latest version and I’m getting the error TypeError: Cannot set properties of undefined (setting 'World') cucumberjs. I didn’t see anything about this in migration or in the issues. Does someone know what might be going on?~ world.js is the one place I’m requiring cucumber, duh. Sorry about that.
*Thread Reply:* if you're going from 6.x it might be smoother to go to 7.x first, then go from 7-8, especially since 8 is only a release candidate at the moment and may not be totally stable.
Sorry, this is my first time doing any kind of major migration, strangely enough.
I do need to set the default timeout dynamically from within a step so that it’ll affect all future steps, but I’m reading the timeout docs and they now say you can’t do it with setDefaultTimeout. Is there any way to do it other than disabling the cucumber timeout and handling it manually in each individual step?
*Thread Reply:* Right now I’m trying to kind of hack it with { timeout: -1 } and wrapPromiseWithTimeout. A bit new to promises. Does someone know if I have to return for it to work? Not sure if I’m doing something else wrong.
I’m making a PR to update the [docs]. Do I need to update CHANGELOG.md? I don’t see other entries for pure documentation edits in the CHANGELOG.
*Thread Reply:* Also, sorry that I’m misusing it so badly. It’s [for a good cause, but still]
Now that I’m using v7, I’m getting that wrapPromiseWithTimeout is undefined . v7.3.2. Sorry to be a pain, but I thought wrapPromiseWithTimeout was a v7 thing (latest stable version), right?
*Thread Reply:* If it’s not functioning, can we still use the global setDefaultTimeout()? I can experiment, I’m just hoping not to run into any gotcha’s later.
Either way, maybe the instructions for using it should be removed from the docs completely until it’s ready.
*Thread Reply:* looking at the changelog, wrapPromiseWithTimeout is from 8.0.0-rc1 - are you able to use that version? https://github.com/cucumber/cucumber-js/blob/main/CHANGELOG.md
*Thread Reply:* Hmm, I’m a little confused on a couple levels here, so I’ll try to articulate.
First, for my package: Since 8.0.0-rc.1 isn’t stable, I’m hesitant to use it for my package. Remembering to update it in the future may be complicated and easy to lose track of as well (esp. since I’m not convinced npm will update properly to the latest stable future version).
For others: Are the docs supposed to be for a non-stable version? Because right now the instructions for customizing a timeout has wrapPromiseWithTimeout.
For the migration docs: I may need to correct my update to the migration docs because they might be wrong at the moment. The v7 migration now says you can’t use setDefaultTimeout in a non-global context. That might not be true for v7. I’m not sure anymore.
*Thread Reply:* Is v8.0.0-rc.1 stable enough to count on for this stuff?
*Thread Reply:* that’s fair, i think it’s best to stay on stable for the reasons you say. in the meantime you could just grab the source of that function for now if its helpful https://github.com/cucumber/cucumber-js/blob/main/src/time.ts#L42
*Thread Reply:* with the docs, yeah the docs in main can include stuff that isn’t released yet. https://github.com/cucumber/cucumber-js/tree/7.x is the right set for the current stable. this is definitely not ideal, we’ll review how to avoid it in future
*Thread Reply:* Our project is also struggling with how to handle multiple stable releases. We still haven’t figured out how to handle the docs for those. Badly, mostly.
*Thread Reply:* We’re thinking of removing the docs from the main branch and just referring to the ones in the specific version branches. At least, anything other than an overview.
I’m seeing change with v7 that I don’t see in the changelog and I just want a reality check. This is going to sound weird.
In v6, when a step failed and our code changed the scenario status to “passed”, the final output would show all scenarios passed, but one step failed. Now it shows all scenarios passed and all steps passed. Is that expected behavior for v7?
[The “F” does still appear in the progress indicator as before.]
*Thread Reply:* that does sound weird! May I ask why you're doing that?
*Thread Reply:* You certainly may! We’re misusing cucumber to write a testing framework for an open source platform that helps people create legal forms. Our team in particular is working on emergency legal forms (restraining orders, eviction stays, etc.), but we’re hoping to help the other users of the platform as well, most of who are pro bono legal services [and don’t have a lot of money or resources].
Most of these developers are actually not coders, [they’re lawyers]. We output reports to developers who run the tests to give them information that are easier for them to understand and have more relevant details. We want to be able to test the reports we output for them, even/especially when they’re describing errors. [That is, failing tests.]
I’m not sure that was a very clear explanation, so let me know if you have more questions.
*Thread Reply:* I'm intrigued, but still puzzled! Can you give me a real-world example?
*Thread Reply:* Very abstract example Scenario our users can write:
Scenario: I get a document
Given I start the interview at "important_form.yml"
When I tap to continue
And I set "user.name.first" to "Maria"
And I set "user.name.last" to "Gonzalez"
And I tap to continue
Then I download "landlord-notice.pdf"
There’s a more “story-driven” step, but it’d be harder to explain.
So, for our error catching, if puppeteer “tapped to continue” and hit an error screen, we’d print the text on the error screen in the report we make. We want to be able to test that our code adds the error text at appropriate times.
Is that the info you were looking for? Also, if you want a real-world example, I can point you to one, but it would be a lot to put here.
Hello, I have a question. Can you check the pattern of a text you get with driver.findElement().getText()? I'm trying to check if the date format is respected(ex : January 28, 2022). Can there be used in some way a regex and the text to be split or is there another easier way?
*Thread Reply:* @Manuela Mag that sounds like a question about Selenium WebDriver. In general it's better to use their forum for questions about that.
@Manuela Mag what assertion library are you using? You can use https://www.geeksforgeeks.org/node-js-assert-match-function/ to assert that a string matches a regex pattern. Or hamjest's matchesPattern https://github.com/rluba/hamjest/wiki/Matcher-documentation#matchespatternstringorregexp
Hi. Am I correct that ESM support was added and then removed again (https://github.com/cucumber/cucumber-js/blob/main/CHANGELOG.md#fixed-5)?
No, ESM has been added in 8.0.0-rc.1 and is still there at the moment
I'm on "@cucumber/cucumber": "^7.3.2", and having an issue with calling run on a new instance of cucumber.Cli
Error [ERRREQUIREESM]: require() of ES Module /usr/src/app/src/steps/steps.js from /usr/src/app/nodemodules/@cucumber/cucumber/lib/cli/index.js not supported. Instead change the require of steps.js in /usr/src/app/nodemodules/@cucumber/cucumber/lib/cli/index.js to a dynamic import() which is available in all CommonJS modules.
import cucumber from '@cucumber/cucumber'; ^^^^^^^^ SyntaxError: The requested module '@cucumber/cucumber' does not provide an export named 'default'
What are you trying to import actually? Indeed cucumber has no default export ... on purpose
Do you have more context? More example? More code? What did work previously?
On version 7.2.1 we could pull in cucumber with: const cucumber = require('@cucumber/cucumber'); . I upgraded to 7.3.2 and used import cucumber from '@cucumber/cucumber'; and it worked fine. Now I upgrade to 8.0.0-rc-2 (as you mentioned that's what we need for ESM) and cucumber can no longer be imported.
Cucumber has not been disigned to be used as a global object.
You need to import what you actually need.
If you need the CLI, something like import { Cli } from '@cucumber/cucumber' should work well.
OK, (We've been using it like this for 4 years) so it's a breaking change, it's just not documented by the looks of it
https://github.com/purpleteam-labs/purpleteam-app-scanner/blob/main/src/api/app/models/app.js#L11
And the thing is that ESM are not working exactly the same as CJS modules.
At least at the moment, there is no way to get a global cucumber object.
and thanks @Aurélien Reeves, it's maintainers like you that really make these problems a lot more bearable.
You are very welcome 🙂
Something else: there is no global cucumber object. But if you had access previously to some API, you sould still be able to access it now. If it is not the case, let us know, that may be an issue
*Thread Reply:* There is actually no documented list of the APIs.
I just meant that if you previously had used something from Cucumber that seems not available anymore because it is not explicitely exported, let us know
import { Cli as CucCli } from '@cucumber/cucumber'; ^^^ SyntaxError: Named export 'Cli' not found. The requested module '@cucumber/cucumber' is a CommonJS module, which may not support all module.exports as named exports.
I think that might be a false alarm, I failed to save a package.json after bumping version... Sorry
Good morning,
We are starting to look into using cucumber have a couple of questions will split them up.
1- What linter is recommended since we want to make sure all of the features/steps follows a standard
*Thread Reply:* I don’t think we have an official answer, but personally I’ve used and contributed to these: • https://github.com/vsiakka/gherkin-lint for linting feature files e.g. how many steps in a scenario, scenarios in a feature, correct use of And/But etc • https://github.com/darrinholst/eslint-plugin-cucumber for linting your JS step code e.g. no arrow functions, prefer one type of expression, etc
Question 2 - We are trying to figure out how to create a POM object to pass in the driver. We are facing an issue with our POM object that needs to be created in each step (require a driver in a constructor), but we want it to initialize once if possible. Moving the creation of the POM out of each step this.driver is null.
What we are trying to do is it possible with the framework?
Below you can see that each step creates a new POM object.
```//SearchPagePom.js const { By } = require('selenium-webdriver');
/* * Locators */ const searchBox = By.xpath('//[@data-a8n="quick-search-input"]'); const searchSubmitBtn = By.xpath('//*[@data-a8n="quick-search-submit"]');
class SearchPage { constructor(driver) { this.driver = driver; }
inputSearchQuery(searchQuery) {
return this.driver.findElement(searchBox).sendKeys(searchQuery);
}
clickSearchBtn() {
return this.driver.findElement(searchSubmitBtn).click();
}
}
module.exports = SearchPage;
//SearchPageTest.js
const assert = require('cucumber-assert');
const SearchPage = require('../../page-objects/searchPage');
module.exports = function () {
//would like to createSearch Page once here but driver is null here this.When(/^I search for "([^"]**)"$/, function (searchQuery, next) { const searchPage = new SearchPage(this.driver);
searchPage.inputSearchQuery(searchQuery);
searchPage.clickSearchBtn();
next();
});
this.Then(/^I should see search result heading as "([^"]**)"$/, function (searchHeading, next) {
const searchPage = new SearchPage(this.driver);
searchPage.getSearchKeyword().then(function (heading) {
assert.equal(heading, "\"" + searchHeading + "\"", next, 'Expected search heading to be ' + searchHeading);
});
};```
*Thread Reply:* You might try setting the driver on your World via a Before hook so that it’s available to each step at the start and you get a new one for each scenario that’s run https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/world.md
*Thread Reply:* so to my understanding then I would add the POM to the world object and expose it as property?
*Thread Reply:* The only concern I have we going to have many POM objects that are exposed and going to be shared across 5 to 10 repos. So the world object may get big and messy quickly. I was hoping to get the POM initialize with the steps file is that still possible using the world object
*Thread Reply:* Yeah so you could have the driver live in the world but then initialise your page object in the step definition using the driver you grab from the world (this) - does that make sense?
*Thread Reply:* somewhat it does that mean i need to do it on each When or Then or just once at the step def?
*Thread Reply:* I was hoping once since not sure how many then and when will exists in each file
@binarymist if you have a suggestion for how we could better document the changes in the release notes for v8, that would be super helpful! It's sometimes hard for us to really get into our users' shoes and explain things from their perspetive.
*Thread Reply:* I’m tempted to disagree on this being a breaking change because it was never documented you could do it and arguably a quirk of CommonJS. But probably useful to call out since we know about it. Perhaps worth starting a new “ESM” heading here with a note about this https://github.com/cucumber/cucumber-js/blob/main/docs/migration.md - would you consider doing a PR for that @binarymist?
*Thread Reply:* Yip, happy to sub PR. I'll get everything working first along with some testing. How far away is 8.0.0?
*Thread Reply:* I don't see anything mentioned in docs about having to pass the env into instantiation of a Cli?
*Thread Reply:* This commit added the env into new Cli: https://github.com/cucumber/cucumber-js/commit/efff3a3516a6fd2f2a77de2f1dd6ac515349e8d6 @David Goss
*Thread Reply:* The CUCUMBER_PUBLISH_ENABLED doesn't appear to be new, but I don't see it mentioned in any doc other than issues, and now it seems it's required by the Cli
*Thread Reply:* It seems that getConfiguration has been remove from Cli somewhere between 7.2.1 and 8.0.0-rc.2. Is there some sort of replacement? Can you help with this @Aurélien Reeves?
*Thread Reply:* Hopefully you'll remember: https://github.com/purpleteam-labs/purpleteam-app-scanner_cucumber-1489-repro
*Thread Reply:* It looks like most of the methods have been removed from the Cli class. getConfiguration was removed in: https://github.com/cucumber/cucumber-js/commit/efff3a3516a6fd2f2a77de2f1dd6ac515349e8d6 and there doesn't appear to be a replacement @David Goss? Where should we find the same functionality?
*Thread Reply:* A lot happened actually as part of the following PR: https://github.com/cucumber/cucumber-js/pull/1849
You may consider taking some time to review it properly. That should help you with integrating with cucumber 8.0+
Actually before then, there were no documented API to execute cucumber programmatically. This is the purpose of the work done as part of v8: having a proper, documented way to interact with cucumber programmatically.
A lot may have changed, but actually you should be able to find the same things than before, they may have just moved.
*Thread Reply:* @David Goss I guess we may consider documenting that new API for the final 8.0.0?
*Thread Reply:* It's interesting that "no breaking changes" is mentioned a number of times in the PR you mentioned @Aurélien Reeves. I guess that part got forgotten in all the excitment?
> A lot may have changed, but actually you should be able to find the same things than before, they may have just moved. It appears as though getConfiguration has been removed rather than "just moved", at least I can't find it in the PR you mentioned. The implementation also appears to be removed rather than "just moved"
I'm really hoping I'm wrong..?..
*Thread Reply:* Can you show an example of how you're using the Cli class? I'm not sure why you'd need to call getConfiguration directly
*Thread Reply:* @binarymist actually what did change was not publicly documented APIs. From a public API point of view, the PR does actually add new things
When hacking on something using non-documented functionalities or internal APIs which are not mean to be used by third parties, you are subject to undocumented breaking changes. This is exactly what happens here.
*Thread Reply:* @David Goss As linked to above: https://github.com/purpleteam-labs/purpleteam-app-scanner/blob/main/src/api/app/models/app.js#L200 and the minimum repro example that @Aurélien Reeves helped with: https://github.com/purpleteam-labs/purpleteam-app-scanner_cucumber-1489-repro/blob/main/src/api/app/models/app.js
*Thread Reply:* OK @Aurélien Reeves, so now that the API has been removed, what should we use instead?
*Thread Reply:* The new one issued from the PR#1849
If something is missing for you, you can take part of the discussion here: https://github.com/cucumber/cucumber-js/issues/1711 or in the PR
*Thread Reply:* The new one appears to be missing the functionality @Aurélien Reeves, does it not? Thanks for the link.
Hi Team, I have spring integration with cucumber, I have created multiple step definition class and all the classes extends ExporterComponentTests
@CucumberContextConfiguration
@SpringBootTest(classes = { TestConfiguration.class,
ExporterComponentTests.TestConfiguration.class},
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@ContextConfiguration()
@AutoConfigureMockMvc
@AutoConfigureWebTestClient(timeout = "30000")
public class ExporterComponentTests
It is working fine with cucumber-spring 6.3.0 version but failing with the latest version saying expected single matching bean but found 8
Can you please point me to a migration document or some example with the latest version? Thank you in advance.
*Thread Reply:* I think you're looking for <#C5YHPPJMP|help-cucumber-jvm> - you should be able to get some support in there
“test:address:stage”: “cross-env NODE_ENV=stage cucumber-js --tags=‘@address and not @pending’“,
*Thread Reply:* which version of cucumber are you using?
latest version may have some improvements regarding windows support
Also what "does not work" mean exactly? Do you have more info? Some error message maybe?
*Thread Reply:* Thanks.
Take a look at the following, there is a workaround for Windows: https://github.com/cucumber/cucumber-js/issues/1796#issuecomment-938405981
The issue is actually related to npm
hey, i am trying to setup cucumber on nodejs server and everything is working 1 issue that i have is im trying to pass some env variables to the run i saw that ppl suggesting to pass it as world-parameters but this is jus adding things to the World instance i have workaround but im hopping theres a better way to do it
*Thread Reply:* Could you give more info about what you are trying to achieve?
You want to update ENV as part of your run? To set some kind of default values, or forcing some specific values?
*Thread Reply:* i want to pass env variable directly to the process.env from the cucumber.js or something similar
*Thread Reply:* Why do you need to do that as part of the cucumber run? Setting appropriate ENV before executing the run is not an option?
Did you tried the BeforeAll hook? (https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/hooks.md#beforeall--afterall)
*Thread Reply:* i wanted it to be as part of the settings and then it can be env changeable but if there is no option i will use the before all
Hi, I’m new to JavaScript but I’m not new to Cucumber — been using the Java version for quite some time. I’ve structured my TypeScript project as follows
├── features
│ ├── greeting.feature
│ └── step_defiinitions
│ └── steps.ts
├── package-lock.json
├── package.json
├── src
│ ├── cucumber-js-example
│ │ ├── cucumber.js
│ │ └── index.ts
│ └── resources
└── tsconfig.json
And, my package.json
{
"name": "typescript-examples",
"version": "1.0.0",
"description": "A collection of TypeScript example 'projects' used for experimentation",
"scripts": {
"test-cuke": "cucumber-js"
},
"dependencies": {
"@cucumber/cucumber": "^7.3.2",
"@types/node": "^17.0.21"
}
}
When I run npm run test-cuke I get the following
```> typescript-examples@1.0.0 test-cuke /Users/stagr005/workspace/typescript-examples > cucumber-js
UU
Failures:
1) Scenario: Say hello # features/greeting.feature:3 ? When the greeter says hello Undefined. Implement with the following snippet:
When('the greeter says hello', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
? Then I should have heard "hello" Undefined. Implement with the following snippet:
Then('I should have heard {string}', function (string) {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
1 scenario (1 undefined) 2 steps (2 undefined)``` I’m not sure what I’ve misconfigured. But, I’m sure I overlooked something. Any guidance would be appreciated
My steps.ts looks like ```import assert from 'assert';
import { When, Then } from '@cucumber/cucumber'; import { Greeter } from '../../src/cucumber-js-example';
interface MyWorld { whatIHeard: string; }
When('the greeter says hello', function (this: MyWorld) { this.whatIHeard = new Greeter().sayHello(); });
Then( 'I should have heard {string}', function (this: MyWorld, expectedResponse: string) { assert.equal(this.whatIHeard, expectedResponse); } );```
I’m working with the CucumberJS code using TypeScript. I’m new to JavaScript. I’ve laid out my features dir per “standard” structure and running the tests work just fine. Here’s what it looks like
├── cucumber.js
├── features
│ ├── greeting.feature
│ └── step_defiinitions
│ └── steps.ts
├── package-lock.json
├── package.json
├── src
│ ├── cucumber-js-example
│ │ └── index.ts
└── tsconfig.json
Is it possible to move the features directory under src/cucumber-js-example directory ? And, if so, what configuration changes do I need to make in order to run the tests?
I tried placing features under src/cucumber-js-example, but that did not work. Each time I run the test, it returns 0 scenarios were executed.
*Thread Reply:* Hey @Robert.S, while as a general rule I would advise leaning into the defaults where possible, you can indeed have your features in whatever directory you like, you just need to tell cucumber by passing one or more globs as the positional arguments. So for your example say you are currently running
cucumber-js <your options>
You’d need to change to
cucumber-js src/cucumber-js-example/features/****/**.feature <your options>
Full docs are here https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md.
*Thread Reply:* @David Goss, thanks for your help and pointing me to the documentation.
It would appear my earlier problem was a result of placing the path to the feature files in the wrong location within the cucumber.js file.
Here is what I had
module.exports = {
default: [
'src/cucumber-js-example/features/****/**.feature',
'--require-module ts-node/register',
'--require src/cucumber-js-example/features/step_defiinitions/****/**.ts',
'--publish-quiet',
'--format @cucumber/pretty-formatter',
].join(' '),
};
*Thread Reply:* And, after you guidance, I updated it to be
module.exports = {
default: [
'--require-module ts-node/register',
'--require src/cucumber-js-example/features/step_defiinitions/****/**.ts',
'--publish-quiet',
'--format @cucumber/pretty-formatter',
'src/cucumber-js-example/features/****/**.feature',
].join(' '),
};
And, it worked 😄 !!!. The path to features has be the last item in the list
*Thread Reply:* note that there are a few examples to refer to here: https://github.com/cucumber-examples/cucumber-js-examples
*Thread Reply:* thanks @matt-SmartBear. That’s the first resource I looked at. Unfortunately, the documentation does not mention anything about required placement of the ‘features’ path within the cucumber.js file
*Thread Reply:* @Robert.S Will it because of the typo in step_defiinitions?
Hi! I'm using cucumber-js and I'm wondering if there is any way to know which tags have been used for filtering within the AfterAll hook? From my understanding the BeforeAll and AfterAll cannot be filtered with tags.
*Thread Reply:* My goal is to only run certain cleanup task in AfterAll if a certain tag is applied. I don't see any way to do that right now.
We’re writing a package that has executables that we’re running with cucumberjs v7.3.2. When a dependent tries to run this script, the Steps are undefined: "./node_modules/.bin/cucumber-js --require ./node_modules/.bin/alkiln-cucumber"
The file to which that code refers is our “./lib/index.js” and this is what’s in that file: ```#!/usr/bin/env node
console.log('\n====\n====\n====\n====\nanything\n====\n====\n====\n====\n'); require('./world'); let foo = require('./steps.js');
console.log('foo:', foo);``` Nodes doesn’t throw any errors, but none of those console logs get logged. Other executables (they don’t use cucumber) work fine [and are in the same directory as the one that’s not logging]. Any ideas? Or maybe questions? Not sure what to include in here.
*Thread Reply:* I'm surprised. The --require should require all JavaScript files in that folder at runtime.
*Thread Reply:* Can you try and create a minimal reproducible example on GitHub?
*Thread Reply:* I would be more surprised if requireing an executable like that worked, they aren’t designed for that. What’s stopping you from providing --require with the paths to the world and steps files?
*Thread Reply:* (I think Cucumber is probably treating ./node_modules/.bin/alkiln-cucumber as a directory not a file path, because it has no extension.)
*Thread Reply:* These lines to run executables are working:
"setup": "node_modules/.bin/alkiln-setup",
"takedown": "node_modules/.bin/alkiln-takedown"
That’s from the dependent’s package.json. Those lead to files, not directories. In our package that looks like:
"bin": {
"alkiln-setup": "./lib/docassemble/setup.js",
"alkiln-takedown": "./lib/docassemble/takedown.js",
"alkiln-cucumber": "./lib/index.js",
}
*Thread Reply:* Small reproducible example: https://github.com/plocket/exec-dependent
*Thread Reply:* Thanks for the repro, added a PR here https://github.com/plocket/exec-dependent/pull/1
*Thread Reply:* Basically anything you pass to --require with no extension will be treated as a directory, not a file path, so you need to give it a path to the actual file(s) you want, not the executable script
*Thread Reply:* Sorry that I didn’t actually repro the right issue and thanks for finding out about --require. Good thing to know in general 👍
*Thread Reply:* No problem! I think issues with configuration like this are too hard to diagnose at the moment, so I'm looking at adding a debug option to make it easier.
Hey all! I'm trying to use cucumber-js 8.0.0-rc.2 with ES modules, and in the docs here: https://github.com/cucumber/cucumber-js/blob/main/docs/cli.md I see there there is an --import option, but when I try to use it, i get the following error:
error: unknown option '--import'
*Thread Reply:* I'm guessing this feature hasn't been released yet? Any ideas when I can start using it?
*Thread Reply:* Hey @Mark W. Oosterveld, rc3 should be out in the next few days with that available
*Thread Reply:* I'm starting a new (hobby) project, and I plan to use ESM and Typescript
*Thread Reply:* Not yet but I’ll be looking at that next. Oddly enough just commented here https://github.com/cucumber/cucumber-js/issues/1844#issuecomment-1066174669
Hi there, What are the best practices used to gracefully fail a test run in the BeforeAll hook when using it with TypeScript? Features with Scenarios should not be executed but the AfterAll hook should be executed.
*Thread Reply:* I don’t think we have a first-class way to support this now, but you might be able to work around it, something like:
```// runs once before everything BeforeAll(() => { process.env.BAILONTEST_RUN = 'true' })
// runs before each scenario and can skip it Before(() => { if (process.env.BAILONTEST_RUN === 'true') { return 'skipped' } })```
*Thread Reply:* This should be a bit less clunky once https://github.com/cucumber/cucumber-js/pull/1770 is finished and we have a global test run context.
Hello, I was wondering if you could help me. What would be the best package for installing the chrome driver? I tried a few, but over time I'm getting this error : SessionNotCreatedError: session not created: This version of ChromeDriver only supports Chrome version 97
Current browser version is 99.0.4844.74 with binary path Is there a way to install it without being dependent on some fixed version of chrome?
*Thread Reply:* Personally I like this package, it allows you to set a property in your .npmrc file that always installs the latest version of chromedriver https://www.npmjs.com/package/chromedriver
*Thread Reply:* Thank you! Could you also tell me which property is that? And how to find that file? I'm using a macOs big sur
*Thread Reply:* No problem! The property is chromedriver_version=LATEST, you would have to create a .npmrc file in your project (that is, assuming your project is a NodeJS one?): https://docs.npmjs.com/cli/v8/configuring-npm/npmrc
*Thread Reply:* It’s worth noting that this package will install chromedriver in your project’s node_modules folder, I personally like that but some people prefer it to be installed globally somewhere
*Thread Reply:* i think it's quite useful to have this file with that property, so I would not have to change manually the chrome version each time it becomes deprecated
*Thread Reply:* What else should the file contain? I'm searching right now some example, but i didn't find a good one yet
*Thread Reply:* It doesn’t need to contain anything else unless you want it to, it only exists to pass config to npm packages when you’re installing, so the file can just have the above mentioned property in it (unless you have other properties you want to override)
*Thread Reply:* Hmm I used to use the latest flag I think, but I reverted to changing versions manually because chromedriver always updates before the latest version of chrome is available for download. 😞
*Thread Reply:* There’s always going to be the potential for the browser and driver versions to get out of sync, the only way I’ve been able to consistently keep them in line is to install Chromium as a dependency in my project as well, and make sure that the version of Chromium matches the version of Chromedriver. Then I can bump them to newer versions at the same time when I choose to do so
*Thread Reply:* Just fyi, that last one (with password) has a typo or two. I think Joe A is right in general, though - it looks like the code isn’t finding that file. Where do you require the different files? And what does your package.json scripts look like?
*Thread Reply:* The file is spelled incorrectly for cucumber to find it without a setting. the image says step-definAtion but cucumber will only look for step_definItion unless you tell it otherwise (I believe)
how can I share the state in the Given When and Then step using cucumber-js?
*Thread Reply:* here is the code snippet: ```When(
'{pronoun} select a country code and provide a valid mobile number',
async (actor: Actor, table: DataTable) => {
const countryCode = table.hashes()[0].countryCode;
const mobileNumber = table.hashes()[0].mobileNumber;
await LoginPage.selectCountryCode();
await LoginPage.enterMobileNumber(mobileNumber);
await LoginPage.continueToOTP();
await LoginPage.waitForOTPToProcess();
},
);
Then('{pronoun} is able to verify using OTP', async (actor: Actor) => {
// need to get the value countryCode and mobileNumber from the When step
const date = new Date();
const timeStamp = date.toUTCString();
<a href="http://console.info">console.info</a>('timestamp : ' + timeStamp + '\ncountryCode: ' + countryCode + '\nmobileNumber: ' + mobileNumber)
const OTP = await LoginPage.readOTP(timeStamp, countryCode + mobileNumber);
<a href="http://console.info">console.info</a>('OTP Number : ' + OTP);
await LoginPage.enterOTPInput(OTP);
});```
*Thread Reply:* This is tipically the job of the world: https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/world.md
How can define connection-config json value in nightwatch browser.assert.equal(data.connection-config.ip,’192.168.1.1’)
Hi, I was wondering if you could help me. I'm facing an issue, because of the info bar "Chrome is being controlled by automated test software" the buttons from the bottom of the page are not visible. I tried this to make the info bar disappear, but it didn't work : var webdriver = require('selenium-webdriver');
var chromeCapabilities=webdriver.Capabilities.chrome()
chromeCapabilities.set('chromeOptions', "disable-infobars");
driver = new webdriver.Builder()
.withCapabilities(chromeCapabilities)
.forBrowser('chrome')
.build(); . Is there another way to make the info bar not appear anymore? I tried as well excludeSwitches: ['enable-automation'] , same results. The bar is still there
*Thread Reply:* I’m not aware of a way to do this, might it be easier to increase the default size of the viewport by the height of the info bar?
*Thread Reply:* I think this is an issue with chrome web driver, not cucumber.
*Thread Reply:* You might have better luck asking on their github or if they have a slack
*Thread Reply:* @Rabin There is a built in support for cucumber in nightwatch itself maybe you can use that
Hi all, I am looking for help on running scenarios in parallel where only single login allowed per user using Cucumber+Selenium+nodejs? I cannot find any solid documentation on this. Or Is it possible using Selenium Grid? Is there any working solution available?
*Thread Reply:* Hard to know without more details but the new functionality (just released in 8.0.0) around custom work assignment might help you https://github.com/cucumber/cucumber-js/blob/main/docs/parallel.md#custom-work-assignment - you might be able to allow parallel execution generally whilst limiting your constrained-user scenarios to one at a time
Hi all, I have been using json formatter in cucumber and sometimes the it throws a type error inside cucumber here: https://github.com/cucumber/cucumber-js/blob/main/src/formatter/json_formatter.ts#L278 it says testStepResult is undefined
Hello, is there a way to get the example id from a Scenario Outline?
Let me explain: let’s assume I have the following test:
```Scenario Outline: eating Given there are <start> cucumbers When I eat <eat> cucumbers Then I should have <left> cucumbers
Examples:
| start | eat | left |
| 12 | 5 | 7 |
| 20 | 5 | 15 |``
At the end of the test, my automation creates aeating.json` file with some output from the test. This works great for Scenario but for Scenario Outline, I would like to end up with 2 output files (one for each scenario in the Scenario Outline):
eating-example-1.jsoneating-example-2.jsonSimilarly, is there a way to get the retry id when running cucumber-js with the retry option?
For example, if I run a test with the command: cucumber-js --retry 2 and the test is indeed retried twice, what can I do so that my test will write 3 files:
test.jsontest-retry-1.jsontest-retry-2.jsonAgain, for my purpose, I need the example id and retry id.
It doesn’t look like I can get either of these values at the scenario level from scenario.gherkinDocument, scenario.pickle or scenario.result.
*Thread Reply:* Haven’t tried to do anything like this yet and someone will probably have better advice. That being said, this sounds like an afterEach hook deal. Creating some function that writes a file. I’m not sure if afterEach hooks will run if you’re doing a scenario outline, or if the tests need to be separate.
*Thread Reply:* Thanks for the reply. I already after that function in place in my After(scenario) hook. I am able to write a file after each scenario completes and I can even append a test case ID generated by cucumber-js using something like:
After((scenario) => {
const filename = `${scenario.pickle.name}-${scenario.testCaseStartedId}`;
fs.writeFile(`./tests-output/${filename}.json`, outputData, (err) => {
if (err) {
throw new Error(err);
}
});
*Thread Reply:* I got the name wrong, it’s AfterStep. https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/hooks.md#beforestep--afterstep
*Thread Reply:* But if you already had something like that in place, you could add state to your cucumber world to keep track of the “id”.
example:
this.counter = 0;
fs.fileWrite(`./tests-output/${filename}_${counter}.json`);
this.counter++;
*Thread Reply:* Yeah, unfortunately, adding a counter doesn’t tell me if the file created is the result of a retry or an example in Scenario Outline.
*Thread Reply:* Is there info about whether the test failed or passed in the after step?
*Thread Reply:* Yes, I can get the following when doing a console.log(result):
*Thread Reply:* {
duration: { seconds: 1, nanos: 971000000 },
status: 'PASSED',
message: undefined,
willBeRetried: false
}
*Thread Reply:* You can use state to manage that as well.
this.isRetry = status === failed;
if (this.isRetry) {
fs.fileWrite(`./tests-output/${filename}_${retry}_${counter}.json`);
}
*Thread Reply:* obviously that code won’t work directly but you get the idea.
*Thread Reply:* I can do something like that. You’re on the right track (we just need to handle the case where status === FAILED but there is no more retry after that i.e. willBeRetried === false ). I was just hoping that cucumber-js offered that out of the box.
*Thread Reply:* That works for the retries. I can implement a similar mechanism for examples in a Scenario Outline. I think we can conclude that a scenario is an example if the scenario name is the same.
Hi, is there a built-in way to run the cucumber-js tests in a data-driven way with an external data sheet? I don’t want to hardcode the data by datatable or scenario outline and examples .
*Thread Reply:* Right now the best workaround is probably to template your feature file and have a pre test step that generates it with your data inlined.
*Thread Reply:* There is a proposal here if you want to weigh in https://github.com/cucumber/common/issues/773
*Thread Reply:* Thanks @David Goss. That’s helpful information.
Right now the best workaround is probably to template your feature file and have a pre test step that generates it with your data inlined.
I think that means setting the data into context for the scenario to use.
*Thread Reply:* No, what I meant was having your feature file exist in your repo as a template (e.g. handlebars or mustache), and having a little script or build step that uses the template to generate a feature file with an examples data from all the data, then running cucumber after that.
*Thread Reply:* ahh, I get what you mean now. Yes, all good, I think there are multiple options. But there is no built-in solution which is what I initially asked for.
Hi. Just upgraded to v8 rc3, and have issues with my custom formatter (.ts). I have it hooked up like this:
``module.exports = {
default:${common} --format progress-bar,
ci:${common} --format ./folder/tcFormatter.ts `
}``
it throws an error:TypeError [ERRUNKNOWNFILE_EXTENSION]: Unknown file extension ".ts"`
and it worked just fine with v7. Any ideas?
*Thread Reply:* I ended up by creating npm package for it, and publishing it to the npm private registy.
*Thread Reply:* But I think we can fix before 8.0.0. I don’t think we anticipated that custom formatters might be written in TS and effectively benefit from ts-node being require’d via --require-module earlier in the process. We should be able to rework to accomodate
*Thread Reply:* here we go https://github.com/cucumber/cucumber-js/pull/1985
*Thread Reply:* @David Goss Thanks for the quick fix! Will check later today
Hi all 👋 , I have a test where I am creating an instance of Cucumber Cli it works but when I try to run all tests together steps becomes undefined as if there is no step definition file provided. I think it’s because not clearing require cache, tried that too doesn’t work do we have any other way to clear supportFiles?
*Thread Reply:* You might find using the new runCucumber API helps with this, since you can load the support code once and use it on multiple runs in the same process
https://github.com/cucumber/cucumber-js/blob/main/docs/javascript_api.md
📢 cucumber-js 8.0.0 is out https://cucumber.io/blog/open-source/announcing-cucumber-js-8-0-0/ - please give it a try and feed back if you can!
Hi folks, I just joined a company that is using cucumber + nightwatch.js. I’ve not used cucumber before so am learning as much as I can. Recently one of our developers changed some of the development files in the repo to typescript files. Our cucumber files are still in js. When I try to run our tests, cucumber can’t find the new typescript files that are dependencies. Has anyone else run into this?
*Thread Reply:* You can configure cucumber.js to require your ts files
*Thread Reply:* I have the following for a repo using ts:
const common = [
"--require-module ts-node/register",
"--require test.setup.ts", // Load hooks
"--require features/stepDefinitions/****/**.ts", // Load step definitions
"--format progress", // Load custom formatter
].join(" ");
*Thread Reply:* @Hatch yes that would be in your cucumber.js config file
*Thread Reply:* you can just pass those options on the CLI if you want to try it out, but it's easier to have them save off as default
*Thread Reply:* Sorry I missed the follow-up question; I could have been more explicit.
Hi folks, we run Cucumber JS tests in our deployment pipeline, which uses AWS CodePipeline / CodeBuild. Since migrating to Cucumber 8 (we're now on 8.1.2) we're seeing the step that uploads and parses the results json file fail with the below message. Has something changed with the formatting of the duration field since versions 7.x?
Error in UPLOAD_ARTIFACTS phase: [system: [error processing report: [/codebuild/output/src381885655/src/reports/system/cucumber.json: json: cannot unmarshal number 253118.99999999997 into Go struct field Result.elements.steps.result.duration of type time.Duration]]]
*Thread Reply:* I should note that I've still got some projects using Cucumber 7 and that upload step passes
*Thread Reply:* I see from the CHANGELOG (https://github.com/cucumber/cucumber-js/blob/main/CHANGELOG.md#changed-4) that this was included in the v8 release: https://github.com/cucumber/cucumber-js/pull/1793
*Thread Reply:* Aha, well spotted! Looks like the number of decimal places should have been capped as part of that work, I wonder if something's regressed since the feedback was addressed?
*Thread Reply:* It seems you are using a tool written in Go to process the json. Is it one issued from cucumber? Or something else?
*Thread Reply:* It’s AWS CodeBuild’s built in test report processor, which I can only assume is written in Go: https://docs.aws.amazon.com/codebuild/latest/userguide/test-reporting.html
*Thread Reply:* Ok, thanks
I guess we may submit an issue there, or even a PR, to support the new duration precision of cucumber-js
*Thread Reply:* I though that was a link to a github repo
Trying to find one. Not sure this is actually open-source
*Thread Reply:* Just submit an issue here: https://github.com/awsdocs/aws-codebuild-user-guide/issues/91
*Thread Reply:* Awesome, thank you! Hopefully that will get the ball rolling on a fix. In the meantime I’ve had to downgrade to 7.3.2, which is a shame
how can I have more than 1 tag expression. I used tagExpression: [‘@universal’, ‘@embedded’], it does not work, it give me this error
*Thread Reply:* test:execute:android] [0-0] at tokenize (/Users/a845751yara.com/dev/sh-usermanagement-native-poc/nodemodules/@wdio/cucumber-framework/nodemodules/@cucumber/tag-expressions/src/index.ts:86:20) [test:execute:android] [0-0] at Object.parse [as default] (/Users/a845751yara.com/dev/sh-usermanagement-native-poc/nodemodules/@wdio/cucumber-framework/nodemodules/@cucumber/tag-expressions/src/index.ts:23:18) [test:execute:android] [0-0] at new PickleTagFilter (/Users/a845751yara.com/dev/sh-usermanagement-native-poc/nodemodules/@wdio/cucumber-framework/nodemodules/@cucumber/cucumber/src/picklefilter.ts:128:37) [test:execute:android] [0-0] at new PickleFilter (/Users/a845751yara.com/dev/sh-usermanagement-native-poc/nodemodules/@wdio/cucumber-framework/nodemodules/@cucumber/cucumber/src/picklefilter.ts:36:22) [test:execute:android] [0-0] at new CucumberAdapter (/Users/a845751yara.com/dev/sh-usermanagement-native-poc/nodemodules/@wdio/cucumber-framework/build/index.js:79:30) [test:execute:android] [0-0] at Object.adapterFactory.init (/Users/a845751yara.com/dev/sh-usermanagement-native-poc/nodemodules/@wdio/cucumber-framework/build/index.js:319:21) [test:execute:android] [0-0] at Runner.run (/Users/a845751yara.com/dev/sh-usermanagement-native-poc/nodemodules/@wdio/runner/build/index.js:83:49) [test:execute:android] [0-0] at processTicksAndRejections (node:internal/process/taskqueues:96:5) [te
*Thread Reply:* here is the complete set of cucumber opts in the wdio config file
*Thread Reply:* // If you are using Cucumber you need to specify the location of your step definitions.
cucumberOpts: {
// <string[]> (file/dir) require files before executing features
require: ['./tests/src/****/**.ts'],
// <boolean> show full backtrace for errors
backtrace: false,
// <string[]> ("extension:module") require files with the given EXTENSION after requiring MODULE (repeatable)
requireModule: [],
// <boolean> invoke formatters without executing steps
dryRun: false,
// <boolean> abort the run on first failure
failFast: false,
// <string[]> (type[:path]) specify the output format, optionally supply PATH to redirect formatter output (repeatable)
format: ['pretty'],
// <boolean> hide step definition snippets for pending steps
snippets: true,
// <boolean> hide source uris
source: true,
// <string[]> (name) specify the profile to use
profile: [],
// <boolean> fail if there are any undefined or pending steps
strict: false,
// <string> (expression) only execute the features or scenarios with tags matching the expression
tagExpression: ['@universal', '@embedded'],
// <number> timeout for step definitions
timeout: 1000000,
// <boolean> Enable this config to treat undefined definitions as warnings.
ignoreUndefinedDefinitions: false,
},
*Thread Reply:* I’m not sure what mapping might be happening with wdio, but for Cucumber the tags config option is a single string, not an array.
You might want something like '@universal and @embedded'
*Thread Reply:* Docs; • https://github.com/cucumber/cucumber-js/blob/main/docs/filtering.md#tags • https://cucumber.io/docs/cucumber/api/#tag-expressions Hope this helps!
*Thread Reply:* (I just fixed a typo in that first doc that made it slightly misleading - apologies if that’s what you were going off!)
*Thread Reply:* it didn’t work. i can only use tagExpression = ‘@embedded’
*Thread Reply:* https://github.com/badeball/cypress-cucumber-preprocessor
*Thread Reply:* I thought that library was deprecated hahaha https://github.com/badeball/cypress-cucumber-preprocessor-deprecated yesterday I saw the URL without "-deprecated" but it said deprecated in its content or my bad, i dont know 😅
Sorry to come here with this question, but I’ve seen a lot of people in here talking about puppeteerjs and I’m not sure where else to go. I’m using puppeteer’s page.on('response'…) listener, but I can’t see any of the console logs I make in there. Does anyone know how I can see those logs? I’m trying to rename a file I download and it’s not working at all - nothing’s happening to the name whatsoever. I’m trying to log to troubleshoot, but I don’t see any logs in the command prompt or in the browser running in headless mode. Here’s the code before I’ve added the logs: https://github.com/SuffolkLITLab/ALKiln/blob/552_artifacts_dirs/lib/steps.js#L214. Strangely enough, I do think the Step does wait for the doc to finish downloading because the process waits the appropriate amount of time before exiting.
*Thread Reply:* Not that I know of. @Aslak Hellesøy would this ever be in scope of our VSCode extension in future?
*Thread Reply:* @Eliav Ran @David Goss there is an issue you can monitor here: https://github.com/cucumber/vscode/issues/69
Hey everyone, I'm trying to get the index of the scenario outline example that is currently running in a Before or BeforeStep hook. Has anyone successfully done this? I can see that there has been some chat around making the API nicer but couldn't find anything else?
*Thread Reply:* Hey, you might want to check the example in this issue https://github.com/cucumber/cucumber-js/issues/1851 which I think might be what you need.
Also, would be great if you could comment there with your use case - we’ll definitely do something to address this, just want to make sure it solves the right problem.
Hello all ! Wondering if someone got cypress cucumber running for a large enterprise application. I started creating this big global gherkin dictionary so it could be used in the tests, but now I just read it is actually discouraged to use global step definitions ? Do any of you create step definitions for each feature file ?
*Thread Reply:* Yep - much more neutral advice there. The Cucumber position is essentially that a global namespace forces you to be deliberate and specific about your terminology, and helps highlight when things get conflated and misused. I think @matt-SmartBear had some good quotes.
*Thread Reply:* There is some more context here: https://github.com/cucumber/common/issues/1949
*Thread Reply:* Ha 🤔interesting discussion/view on things. I might indeed start out to let the team write more feature specific gherkin, and avoid hacky generic language. Thnx for the link !
Guten tag! "Guys" is easily replaced with the more gender-neutral "Folks" or "All". We'd appreciate if you tried to use that. Thanks!
Hi all, which cucumber formatter can output a simple summary to a json or text file? All I want is how many tests failed. I then will let CI to post it as a Slack message.
Like:
3 tests failed out of 10
I tried to use summary formatter, like
--format summary:report/summary.txt
But the output contains a lot of special characters & shell color code, which was rejected by Slack.
*Thread Reply:* hmm - it shouldnt include the ascii color stuff if you direct it to a file. which version of cucumber-js?
*Thread Reply:* Like build mine own report by using messages? I just don't quite understand how messages works for this.
*Thread Reply:* The docs https://github.com/cucumber/common/tree/main/messages is not built for that purpose I think.
*Thread Reply:* try the latest (8.2.2) - we put some better handling in for when (not) to emit colors based on the output stream and other stuff
*Thread Reply:* (sending the summary formatter to a file seems a good low effort way to do this. but yeah you could do a custom formatter also)
*Thread Reply:* I just couldn't find a straightforward tutorial/example for how to use message to build my custom report.
*Thread Reply:* I guess some API changed in V8? I now get error Error: Cannot find module '/node_modules/@cucumber/cucumber/lib/formatter/helpers.js'
*Thread Reply:* cool. I can see the special chars & color code are gone.
*Thread Reply:* parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 9, column 24
still fail on slack
*Thread Reply:* I think it's due to some jq and JSON format issue in the Slack integration. I end up writing my own from parsing the old JSON formatter.
*Thread Reply:* When I console log in various places in the Before() callback, all the logs get logged.
*Thread Reply:* This package has been working for a while and this is a new bug. I’m not sure how to track it down because there’s so little information. It’s a pretty big package. Is there more I can tell you?
*Thread Reply:* Hmm, Slack changed. Can’t find how to add a code snippet, so this’ll be a long code block…
*Thread Reply:* ```git diff diff --cc .github/workflows/testtests.yml index 8643da4,97f6f16..0000000 --- a/.github/workflows/testtests.yml +++ b/.github/workflows/test_tests.yml diff --cc action.yml index aadaccc,c700978..0000000 --- a/action.yml +++ b/action.yml diff --cc lib/scope.js index 61a15db,e409330..0000000 --- a/lib/scope.js +++ b/lib/scope.js @@@ -60,21 -63,7 +63,25 @@@ module.exports = let scenario = await scope.makeSureReportPartsExist( scope ); scenario.lines.push({ type, value });
Report:\ntype: ${ type }, value: ${ value }\n);
++// <<<<<<< HEAD_alkiln_test-misc_artifacts/unit_tests_logs-${ date }.txt };\nReport:\ntype: ${ type }, value: ${ value });_alkiln_test-misc_artifacts);\nReport:\ntype: ${ type }, value: ${ value });\nReport:\ntype: ${ type }, value: ${ value });
++// } catch (err) {
++// fs.mkdirSync(_alkiln_test-misc_artifacts);
++// fs.appendFileSync(scope.paths.debug_log, \nReport:\ntype: ${ type }, value: ${ value });
++// }++// =======
++ log.addtodebuglog( Report:\ntype: ${ type }, value: ${ value }\n, scope.paths.debuglog );
++// >>>>>>> releases/v4
return scenario;
}, // Ends scope.addToReport() @@@ -504,6 -478,44 +511,45 @@@ await scope.tapElement( scope, elem, tab_id ); },
page_id, value: ${ id }, });aXe_failure_${ scope.page_id }}) + '.json';fs.writeFileSync( axefilename, JSON.stringify( axeresult, null, 2 ));
++ fs.writeFileSync( ${ scope.paths.scenario }/${ axe_filename }, JSON.stringify( axe_result, null, 2 ));
Found potential accessibility issues on the ${ scope.page_id } screen. Details in ${ axe_filename }.;error,info, value: Accessibility on ${ scope.page_id } passed!})tapElementBySelector: async function ( scope, selector, waitForTimeout ) {
let elem = await scope.page.$(${selector});
let error_msg = Couldn't find "${selector}" on the page, is there a typo?;
diff --cc lib/steps.js
index 3a9a326,c59032e..0000000
--- a/lib/steps.js
+++ b/lib/steps.js
@@@ -18,9 -18,8 +18,10 @@@ const { v4: uuidv4 } = require('uuid')
// Ours const scope = require('./scope');
const log = require('./utils/log'); const sessionvars = require('./utils/sessionvars'); +const makeartifactsfolder = require('./utils/makeartifactsfolder' ); + /** Of Note:
We're using **= because sometimes da text has funny characters in it that are hard to anticipate
**/
@@@ -92,13 -77,9 +94,15 @@@ Before(async (scenario) =>
scope.scenarioid = uuidv4();
scope.expectedstatus = null;
scope.expectedinreport = null;
++ console.log(1);
await scope.addReportHeading(scope, {scenario}); scope.base_filename = await scope.getSafeScenarioBaseFilename(scope, {scenario});
${ scope.paths.artifacts }/${ scope.base_filename }-${ date };${ scope.paths.scenario }/report.txt;fs.mkdirSync( scope.paths.scenario ); ++ console.log(2);
// Downloads scope.downloadComplete = false; @@@ -107,8 -88,10 +111,12 @@@ scope.device = 'pc'; scope.activate = clickwith[ scope.device ]; scope.disableerror_screenshot = false; ++ console.log(3);
scope.page_id = null;
scope.passedallfor_a11y = true; ++ console.log(4);
// Reset default timeout scope.timeout = 30 ** 1000; diff --cc tests/features/observationsteps.feature index 5c5646f,d09cd3f..0000000 --- a/tests/features/observationsteps.feature +++ b/tests/features/observationsteps.feature @@@ -123,7 -123,7 +123,7 @@@ Scenario: I get the page's JSO Given I start the interview at "alltests" Then I get the page's JSON variables and values
@fast @o9 @screenshot -@fast @o11 ++@fast @o11 @screenshot Scenario: I take a screenshot Given I start the interview at "all_tests" Then I take a screenshot diff --git a/lib/utils/log.js b/lib/utils/log.js index ee9960e..3ec329c 100644 --- a/lib/utils/log.js +++ b/lib/utils/log.js @@ -51,8 +51,24 @@ log.debug = function ({ type='', pre='', data='', post='' }) { } };
-log.addtodebuglog = function(value) {
- fs.appendFileSync(log.debuglogfile, value);
+log.addtodebuglog = function(value, pathname) {
+ /* Try to add value to file at optional path. On failure, try to add to file at a default
+ * directory. If that doesn't exist, make that default directory and then put log there.
+ *
+ * This complexity is mostly for unit tests, which don't otherwise go through the artifact
+ * folder creation process. */
+ try {
+ fs.appendFileSync(pathname, value);
+ } catch (err) {
+ try {
+ fs.appendFileSync(${ log.fallback_debug_dir }/${ log.debug_log_file }, value);
+ } catch (err) {
+ console.log( err );
+ fs.mkdirSync( log.fallbackdebugdir );
+ fs.appendFileSync(${ log.fallback_debug_dir }/${ log.debug_log_file }, value);
+ }
+ }
};
log.debuglogfile = 'debuglog.txt'
+log.fallbackdebug_dir = _alkiln_test-misc_artifacts;```
*Thread Reply:* I can commit it to a different branch and push it there. That may take a bit.
*Thread Reply:* I’m just going to look at what changed from when it was working to now and debug it that way.
*Thread Reply:* This is the branch: https://github.com/SuffolkLITLab/ALKiln/tree/552_artifacts_dirs
*Thread Reply:* This is the branch I’m merging into it: https://github.com/SuffolkLITLab/ALKiln/tree/releases/v4
*Thread Reply:* Can you open a pull request between the two branches, so I can see the diff?
*Thread Reply:* https://github.com/SuffolkLITLab/ALKiln/pull/567
*Thread Reply:* Nothing super obvious jumps out. there’s a lot going on in the before, hard to tell what could possibly be causing it
Is it possible to repeat a Scenario only on a specific kind of failure? [Not just a specific kind of tag.]
*Thread Reply:* Or flag a specific Scenario for retesting [while that scenario is being run]?
*Thread Reply:* Not at the moment. Only tags can influence whether retry kicks in.
*Thread Reply:* No, those only come from the feature files.
Hey there, since updating from cucumber-js version 7 -> 8, I've been encountering an error whereby the duration values in the cucumber_report.json are decimal values which is causing errors in my AWS Stack, is this a configurable setting where I can prevent decimal values? I can provide screenshots shortly.
*Thread Reply:* Hi Tom,
This is a known thing. It has been discussed a few weeks ago here: https://cucumberbdd.slack.com/archives/C6QJ6N695/p1651483291178619
As you can see, I have submitted an issue to AWS, but it seems they do not care about it 😢
From our side, right now we have no plan to revert our changes
However if someone submit a PR to add an option that would disable the performance counter on demand, I guess that would be accepted
*Thread Reply:* do you think you could open a feature request suggesting that here: github.com/cucumber/cucumber-js/issues?
*Thread Reply:* Hey Aurélien, thank you for the quick reply.
To confirm, you want me to create a feature request on the cucumber github to add a config to disable the duration counter?
I'm happy to do that I just want to be sure 😄
*Thread Reply:* https://github.com/cucumber/cucumber-js/issues/2086
Please see this and let me know if it's satisfactory
*Thread Reply:* I forgot to mention, I actually raised this directly with AWS support a few days ago after not hearing anything on the GitHub issue. This was the reply:
```Hello,
Thank you for contacting AWS Premium Support. My name is Kieran and I will be assisting you today!
I understand on upgrading Cucumber-js to version 8.0, CodeBuild began failing with the following message:
—— Error in UPLOAD_ARTIFACTS phase: [system: [error processing report: [/codebuild/output/src381885655/src/reports/system/cucumber.json: json: cannot unmarshal number 253118.99999999997 into Go struct field Result.elements.steps.result.duration of type time.Duration]]] ——
I have researched the 'cannot unmarshal number' message on my side and can see that this is a known Golang issue which you can read more about here [1]. The error here describes the JSON duration being unable to be marshalled to the 'time.Duration' type.
As this is a Golang issue and not a CodeBuild issue, unfortunately, this falls outside of AWS' Scope of Support [2].
However, I have looked further into the issue. Please see the blog post [3] discussing marshalling methods for Go. It includes example code for handling of numeric or string representations.
I hope our chat today helped. If you have further concerns or queries, please do not hesitate to reach out. I am always happy to help!
Have a great day!``` I’m going to push back, as it’s their json parser that has the issue
*Thread Reply:* @Jim Trenowden do you have a link or case # for that case you raised with AWS? I might have a way to get it in front of the right people.
*Thread Reply:* Great, thanks! Let me see what I can do.
*Thread Reply:* Hi @David Goss did you have any luck with escalating this to the right people at AWS?
*Thread Reply:* Yes, somewhat. For now they’re going to call out 7.x as their highest supported cucumber-js version, and a fix for the unmarshalling error is on their backlog - no timescale though
*Thread Reply:* Ace, thank you. Is the plan currently to implement the opt-out option you spoke about before or wait for AWS to address the error on their end?
*Thread Reply:* To be honest I’m minded to just change the JSON formatter to Math.floor those timestamps rather than make an option. I think this was a regression/oversight on our part (core team) that we should correct. Hopefully AWS will also make their code more flexible and then the affected versions will work for them as well.
*Thread Reply:* That's awesome, do you anticipate a timeframe for this? Appreciate there's a lot you folks do just so I can take it back to my boss 😄
*Thread Reply:* Salutations Earthling! "Guys" is easily replaced with the more gender-neutral "Folks" or "All". We'd appreciate if you tried to use that. Thanks!
*Thread Reply:* https://github.com/cucumber/cucumber-js/pull/2094 - hoping to get this in and released in the next couple of days
*Thread Reply:* https://github.com/cucumber/cucumber-js/releases/tag/v8.5.1
*Thread Reply:* No worries! Let me know if that makes your issues on CodeBuild go away. The team at AWS kindly added this to their backlog, but if it’s fixed from our side I can tell them not to worry.
*Thread Reply:* I’ll try updating our project now, I’ll let you know what happens
in my project i have step that create my app and it is dependent on world parameters in order to inject environment variables that is forcing me to use Before instead of before all is there a way to inject the env var into the process in another way right now i do it in this order and the initialize my app
*Thread Reply:* This overlaps with https://github.com/cucumber/cucumber-js/issues/1393 - there’s a change being worked on now where BeforeAll would have access to world parameters.
*Thread Reply:* In the meantime probably the least worst thing to do is to use actual environment variables I.e. set them outside of the cucumber process
suggestion from product owner on my team. Display all types of status in html report (We should know them).
Hi folk,
I'm a newbie starting out on my cucumber-js journey and I was wondering if there were any examples of a configuration file that could be used to run tests against multiple browsers. I think that I need to setup profiles then somehow pass the name of each browser to the CLI?
*Thread Reply:* Welcome @UoB software developer 👋
You’re right that profiles is a good tool for this kind of thing. You might have your configuration file be like:
{
"chrome": {
"worldParameters": {"browser": "chrome"}
},
"firefox": {
"worldParameters": {"browser": "firefox"}
}
}
And then pick that up in a custom World class that spins up your browser instance:
if (this.parameters.browser === 'chrome') {
// spin up chrome
}
// etc
*Thread Reply:* @David Goss Thanks for the response. Great tip. I'll try this!
I'm stuck getting Typescript to work using Babel to control transpiling.
*Thread Reply:* babel.config.json
{
"presets": ["@babel/preset-env", "@babel/preset-typescript"]
}
*Thread Reply:* cucumber.json
{
"default": {
"publishQuiet": true,
"requireModule": [
"@babel/register"
],
"require": [
"steps/****/**.ts"
]
}
}
*Thread Reply:* package.json
{
"name": "@ucx/cucumber-screenplay",
"version": "1.0.0-beta.3",
"description": "Cucumber Screenplay support libraries",
"main": "dist/index.js",
"type": "module",
*Thread Reply:* tsconfig.json
{
"files": ["src/index.ts"],
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"outDir": "dist",
"esModuleInterop": true,
"strict": true,
"typeRoots": ["node_modules/@types", "./src"],
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true
},
"include": ["src/****/**"],
"exclude": ["src/****/**.spec**"],
*Thread Reply:* Do you have details of what goes wrong e.g. stack traces?
*Thread Reply:* At first glance I notice you’re using requireModule and require in your config and your module format in tsconfig is commonjs, but then you have type: "module" in the package.json - this could be an issue but not totally sure.
*Thread Reply:* Starting over (ignore the above, I've been editting). This is the script invocation in the package.json:
"scripts": {
"test": "cross-env NODE_OPTIONS=\"--loader ts-node\" cucumber-js",
*Thread Reply:* Currently using a cucumber.cjs to configure cuke with this:
module.exports = {
default: {
publishQuiet: true,
requireModule: [
"ts-node/register"
],
require: [
"steps/****/**.ts"
]
}
}
*Thread Reply:* tsconfig.json:
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"declaration": true,
"outDir": "dist",
"esModuleInterop": true,
"strict": true,
"typeRoots": ["node_modules/@types", "./src"],
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true
},
*Thread Reply:* And when I try to run: ```PS C:\Users\tendo\Projects\ucx\mfa\tests\cucumber-screenplay> npm test
> @ucx/cucumber-screenplay@1.0.0-beta.3 test > cross-env NODE_OPTIONS="--loader ts-node" cucumber-js
(node:24552) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
(Use node --trace-warnings ... to show where the warning was created)
Error [ERRREQUIREESM]: Must use import to load ES Module: C:\Users\tendo\Projects\ucx\mfa\tests\cucumber-screenplay\steps\init.ts```
Ok, I'm down to this - I thought the ESM bugbear was fixed? Error [ERRREQUIREESM]: require() of ES Module C:\Users\tendo\Projects\ucx\mfa\tests\cucumber-screenplay\test-build\index.js from C:\Users\tendo\Projects\ucx\mfa\tests\cucumber-screenplay\node_modules\@cucumber\cucumber\lib\api\support.js not supported.
K, got it. I overlooked that there's now a difference between --require and --import
When I have some time I'll revisit the docs to make this more obvious somehow.
K, looking at the docs, I did flat out overlook this so it isn't the fault of the authors of the doc file. I'll move this to committers-js for improving this.
What is the datatype of the scenario variable passed into a BeforeHook (and several others)?
I got these customer parameter types set up so that I can specify any name for listener and shouter. Great. What I fail to understand is this: If transform automatically creates a new Person type, where is that actually being used? I still need to create my own in the step definitions so that it's associated with this. So, what is the benefit of the return from the transform fxn.?
*Thread Reply:* ```import { defineParameterType } from "@cucumber/cucumber";
defineParameterType({ name: "listener", regexp: /[a-zA-Z]+/, });
defineParameterType({
name: "shouter",
regexp: /[a-zA-Z]+/,
});``
Works same.transform` not doing anything here.
*Thread Reply:* ```import { defineParameterType } from "@cucumber/cucumber";
const names = ["listener", "shouter"];
names.forEach((name) => { defineParameterType({ name, // name of the parameter type regexp: /[a-zA-Z]+/, // regular expression to match the parameter }); });``` More DRY. 🤓
*Thread Reply:* You can access this from the transform function too, so you can set this.listener or this,shouter in the parameter type, if you want to.
*Thread Reply:* The idea of the transform function is to turn the string from the regexp capture into something more meaningful and useful in your domain,
I think I've bumped into a serious problem. This config doesn't work:
module.exports = {
default: {
publishQuiet: true,
requireModule: ['@babel/register'],
import: [
"steps/****/**.ts"
]
}
}
*Thread Reply:* If I require instead of import I get a different error.
*Thread Reply:* The only way I've been able to get this to work is to compile the cucumber steps to the file system manually instead of JIT.
*Thread Reply:* The problem seems to be there is no importModule directive that parallels requireModule
*Thread Reply:* I m using Babel and using import without issue. LMK and I can share some snippets. I m using Jest with 🥒
*Thread Reply:* Maybe we could work towards a new example in https://github.com/cucumber-examples/cucumber-js-examples ?
*Thread Reply:* This example uses ts-node, perhaps you two could put together a working example for typescript and babel?
https://github.com/cucumber-examples/cucumber-js-examples/tree/main/examples/typescript-node
*Thread Reply:* Yeah. Possibly. M not using TS, but I will post back with something.
*Thread Reply:* > The problem seems to be there is no importModule directive that parallels requireModule https://github.com/cucumber/cucumber-js/blob/main/docs/esm.md#transpiling
*Thread Reply:* I've been quiet cause I'm still fighting with this. When I have a solution I'll look to helping communicate it.
*Thread Reply:* I'm inexperienced with typescript, so I don't know how much of my problem is that inexperience.
*Thread Reply:* Well, I might suggest leaving TS alone and just focus on the JS part first. Certainly, TS is important, but maybe only pursue one at a time for learning.
*Thread Reply:* I've already built a testing framework up in just JS and maintained it for nearly 2 years now. I want to incorporate TS because we are migrating the rest of the codebase to TS
*Thread Reply:* @matt-SmartBear Still looking into getting the example stuff together. It would be after Labor Day (about 2 weeks or so) before I get to it.
*Thread Reply:* Nice one @Manav Misra - I've been on vacation until now myself. If you want to pair on it, hit me up at calendly.com/mattwynne/
*Thread Reply:* Crazy busy - looking for new position and such...but being as this is Hacktoberfest, I will carve 🎃 out some time for this. 🤓
Hi, I have issue with using cucumber expression. I get the step defn not defined. here is the step definition https://github.com/LayMui/RNLogin/blob/master/tests/src/step-definitions/azureADAuth.steps.ts#L10 and the issue seen https://github.com/LayMui/RNLogin/blob/master/Issue.md thanks
*Thread Reply:* If you use {string} in your expression, then the value has to be enclosed in double quotes. For matching without quotes, try using {word} instead:
*Thread Reply:* thanks this is fixed with {word}. I miss out this
*Thread Reply:* 👋 the readme should get you to a simple hello world that runs and passes https://github.com/cucumber/cucumber-js#readme
Is your question more around how to automate against the React app? Are you thinking of testing at the component level (eg with testing-library), or working it from the outside with a browser driver?
*Thread Reply:* Mostly I'm looking for a starting point for outside in BDD style in a create-react-app
*Thread Reply:* Okay so here's a starter you might find useful https://github.com/davidjgoss/cucumber-puppeteer-typescript-starter
*Thread Reply:* There are some more current ones from others that use playwright not puppeteer, which I think is an improvement.
*Thread Reply:* i would prefer Gherkin over native JS stuff
*Thread Reply:* wouldn't it be possible to build a template for create-react-app?
Hello, I am a tester writing cucumber js script … I am encountering an error : function timed out , ensure promise resolves within 5000 ms How do I resolve it?? Though The script executes next steps even after the above error
*Thread Reply:* See https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/timeouts.md
Hi, in parallel mode, afterAll hook will be called in each worker process. Do we have a way to run something after all workers' processes are completed?
I was having my HTML reporter generate task in an afterAll before I implemented the parallel. It should be only called once and need to wait for all workers to be completed.
*Thread Reply:* We have an issue for this with an agreed way forward in https://github.com/cucumber/cucumber-js/issues/1153#issuecomment-657899146 but it hasn’t been implemented yet. There’s some other work in flight relating to test run hooks, after that’s done I’ll probably pick this up next (but if you feel like giving it a go in the meantime, go ahead!). There are some workarounds mentioned by other users in the ticket which may or may not be useful.
*Thread Reply:* Hi @David Goss that's great to see some work has been done already. Not sure what I can help with. I may need a clear guide. Thanks.
*Thread Reply:* @Tim Yao if you want to pair, https://calendly.com/mattwynne and we can figure it out together
*Thread Reply:* probably like Melbourne afternoon, seems we are both working.
*Thread Reply:* I'm on PST, so my guess is it's more your morning / my afternoon?
*Thread Reply:* I am also facing the same issue, I want to run some tests in before all and after all in one thread in parallel, kind of one time setup in suite level, Can anyone help me to sort this issue.. Thanks..
Hello , I have an issue with using Before all statement in multiple steps_definition file. Which is calling every BeforeAll statement when I run one specific scenario ( that will call only one cucumber step definition having Before All) How do I fix this issue?
Am I not suppose to use multiple time beforeAll in different step-definition files.
*Thread Reply:* What are you trying to achieve?
BeforeAll hooks will run at the start of a test run always. It doesn't matter which file they are defined in and/or if any of the running steps are in the same file.
*Thread Reply:* It sounds like you might want a Before hook which can be targeted at specific scenarios via tags
*Thread Reply:* I have two feature file and different step definitions according to feature I'm running. Now the issue is in each step definition I have defined the before all tag. Unfortunately a weird issue is occurring where it runs the before all , of all the step definition.
When I commented out one before all hook I don't see the above mentioned issue.
*Thread Reply:* Like I said, BeforeAll hooks aren't tied to steps at all. They always run regardless of which scenarios you've filtered to.
*Thread Reply:* This issue got resolved after I used tagged hooks. Thank you all
*Thread Reply:* Do you mean each scenario annotated?? If yes , no I'm not looking for that yet.. The scenario is I have multiple feature file… running one feature file calls all before hooks from different feature file
*Thread Reply:* Seems your answer will solve my question… as I read some issue and solution suggested was to “ if I want to run the hook only for certain feature, need to use conditional hook”
*Thread Reply:* Please give some examples as I don't understand how to tackle this
Hello ,
I wanted to know how can I assert for ‘elementNotExisiting’ or I want to make sure that element is not present on UI
*Thread Reply:* Hello, your question has actually nothing to do with cucumber itself. The answer depends on your assertion library....
*Thread Reply:* Hello , I do understand it’s about assertion and I don’t know how to assert for the exceptions. Can you help me on this?
*Thread Reply:* Chandrika, I cannot help you as I dont have any detail information about what assertion library you use. Check the docs of your asserting library and of the tool you use for instructing the browser.
*Thread Reply:* Good, so look for the answer here: https://www.chaijs.com/api/
Hello , I did try on driver.actions().doubleClick(webElement)
But the above code doesnot do the required action (I.e. Double click on webElement) .
And basically webElement is a data in data grid or table .
TIA
Hi Team How to write the parameters for runCucumber method? Is there any samples available please share @David Goss
*Thread Reply:* Check out https://github.com/cucumber/cucumber-js/blob/d46c797aba67d36b5f446d202667d9d554b81462/docs/javascript_api.md
Hi, I'm trying to run cucumber-js with Typescript. I followed the documentation, but I got an error "Cannot use import statement outside a module". It seems like babel isn't working correctly but I couldn't figure out how to fix it. Could you help me? A minimum reproducible example is here: https://github.com/Hajime-Suzuki/cucumber-ts-issue Thank you in advance! 🙇
*Thread Reply:* Looks like babel needs a bit of extra config to work with ts files, I raised https://github.com/Hajime-Suzuki/cucumber-ts-issue/pull/1 which makes it work.
Hi all, in Behat PHP we can use same scenarios to drive multiple contexts like domain model, application service and even API or e2e tests, however, I'm unable to find how to achieve this using cucumberjs, any help will be appreciated!
*Thread Reply:* the solution that I found till now is to make a different configuration file for each layer/type of steps for example cucumber.domain.json for domain model and cucumber.acceptance.json for application services
*Thread Reply:* A single configuration file with profiles would probably work https://github.com/cucumber/cucumber-js/blob/main/docs/profiles.md
*Thread Reply:* Worked like a charm, thank you again
Hello, what is the best way to set up a fake timer per feature (if possible)? I would like to use a different timer in each file like below ```// steps/a.ts import FakeTimers from '@sinonjs/fake-timers'
let clock Before(() => { clock = FakeTimers.install({ now: new Date('2022-10-29T10:15:34') }) })
After(() => { clock.uninstall() })
Given('...')
When('...')
Then('...')
// steps/b.ts
import FakeTimers from '@sinonjs/fake-timers'
let clock Before(() => { clock = FakeTimers.install({ now: new Date('2022-08-08T10:15:34') }) })
After(() => { clock.uninstall() })
Given('...')
When('...')
Then('...')``
However, when I run the tests I get an error message sayingCan't install fake timers twice on the same global object.` It seems like every step file is executed in parallel, but I wonder if there is any way to isolate them.
*Thread Reply:* Do you really need two separate clocks? I’m not sure this is possible from reading the Sinon docs, as that install method patches some global methods like setTimeout.
*Thread Reply:* Assuming you can share one clock, just use a single set of Before/After hooks and have them set/use this.clock
That will set the clock property on the “world” which is this in each of your steps.
*Thread Reply:* It might be better to put those hooks in a file like features/support/clock.js rather than a step file, though that’s up to you. Cucumber just loads all of those files and how you organize your code in them is your choice.
*Thread Reply:* Thank you for your reply 😀 Let’s say I want to test 2 different scenarios where the date is in the past and future.
When I use this.clock to set date for the 2 cases in the Before, are those dates isolated? I observed Before was called for each step definition file in parallel. I might see the future date in the test where I need the past date.
I’m very new to cucumber, and I miss important concepts. But this is what I’m struggling with now
*Thread Reply:* My understanding is that when Cucumber runs scenarios in parallel, they run in isolated processes so you won't get any clashes.
Can you give it a try and let us know how you get on?
*Thread Reply:* Hi @matt-SmartBear, sorry my slow response. I tried to run my tests in parallel but this was not isolated 😞 Here is a reproduction of my issue. https://github.com/Hajime-Suzuki/cucumber-ts-issue
The documentation says BeforeAll and AfterAll are isolated. Maybe Before and After are not.
Hello , Is there a way where I call stepdefinition implemented in other stepdefinition step. So I don’t have to write steps redundant when the purpose is already achieved in other stepdefinition.
*Thread Reply:* you can move the logic to function and call the function from both steps
<#C6QJ6N695|help-cucumber-js>
Hi everyone!
I'm using cucumber js with node (v16.13.2) to test my application for a while.
I have implemented a kafka consumer within kafka-js npm package, which is running in the background of the application (initialized in the app.ts).
I built a step to wait asynchronously for the task of the consumer to finish, but it seems like it hangs the whole application, and only after getting to the step timeout definition - the consumer back to work.
Is there anything I missed?
Then('There are failed retries with kafka', async function (this: World) {
while (!senderService.HasNumberOfFailedRequests(4)) {
await setTimeoutAsync(3000);
}
});
Hello ,
I want to do some one time data setup for my cucumber js test automation while the tests are running in parallel. so I am using setParallelCanassign function in my hooks class, but I get setParallelCanAssign is not a function error, Can anyone help me how the method should be created to avoid this error. pls note that I imported this function too <#C6QJ6N695|help-cucumber-js>
I'm using cucumber-js, why all the remaining scenarios in are getting skipped after 1st scenario fails? I also tried --fail-fast false .
Hello, Is it true that every time there is an upgrade to an APP or tool that we are automating needs the selenium scripts (using cucumber + JavaScript) to be updated with elements as well?
Even you need update scripts (node) when chrome updates?
*Thread Reply:* Hello, if the selectors do change, then of course you need to update your tests. For this reason you should have good selectors strategy and collaborate with the devs on this.
*Thread Reply:* Hi, Thank you for your response. We mostly use xpath as selector that includes classnames/ids which sometimes gets changes. Do you have any other strategy?
*Thread Reply:* Xpath is usually not the best approach, have a look here :https://playwright.bootcss.com/python/docs/selectors#best-practices This should give you an idea
Hi All, I recently started working on cypress cucumber. How can I run several scenarios for various grids page in the same feature file? Three Hyperlinks [users, clients, and customers] are on one page. Each link when you click it loads a new grid of data with reports and date-picker components.
For example: I have Users link, clients link and customers link . Each tab(page) has reports and a datepicker calendar.
Report.feature contains the following scenarios scenario1: generate a recurring monthly report scenario2: generate a recurring weekly report scenario3: generate a one-time report
All of the scenarios should run for one grid initially, go to another grid, and finish three scenarios. I want to send user grid input, client grid input, and customer grid input in a single feature file.
Thanks in advance.
Hi All, Is there any way to access world parameters in before all method? <#C6QJ6N695|help-cucumber-js>
*Thread Reply:* No, because when that hook eval's there's no world yet.
*Thread Reply:* We're working on it. See https://github.com/cucumber/cucumber-js/pull/1770
Hi All, Cucumber js tagged after hooks are not executing in reverse order, Is there any way to control the tags in specific order, Please help <#C6QJ6N695|help-cucumber-js>
*Thread Reply:* The order that hooks are run in is based purely on the order they were defined in, and tags don't have any bearing on that. If the hooks are in multiple files, the order the files are loaded in will influence it. It's pretty common for people to group all their hooks together in one file to remove ambiguity around ordering.
the order of the code being read in will likely give you the greatest control here.
~Hi everyone!~ ~I unfortunately did not realise this channel existed. If anyone could have a look at my question below, it would be much appreciated~ 🙏
https://cucumberbdd.slack.com/archives/C60TKS3SL/p1675330636636339
See the last comment on that message, thank you all!
Hi there again 🙂 Need your help with a simple question, if possible!
I'll playing around with the paralell option in cucumber-js and to conditionally run the tests in parallel
I'm trying to access the CUCUMBER_WORKER_ID but as you can see in the example use-case (with 2 extra console.logs)
```// This prints the CUCUMBERWORKERID correctly: 0 | 1 | 2 | ...
console.log("Outside -> Works", process.env.CUCUMBERWORKERID);
setParallelCanAssign((pickleInQuestion, inProgress) => { // Prints: undefined console.log("Inside -> Does not Work", process.env.CUCUMBERWORKERID);
return dontRunPicklesWithTag(pickleInQuestion, inProgress);
});``
I'd like to look at the tag (e.g.WORKER1`) and depending on the WORKER_ID running, return false or true
However, given that inside setParallelCanAssign I'm getting undefined I can't do it atm, what would the best approach be?
Thanks in advance!
*Thread Reply:* The worker is env variable won’t be present because the custom assignment code is running on the coordinator not the worker.
Putting the code to one side, could you say more about what you’re trying to achieve here?
*Thread Reply:* Hey @David Goss , Thank you for looking at this
My case is simple, I want to run certain scenarios per specific runners. Example
@Worker_1 Scenario …
@Worker_2 Scenario ...
I’ve made some changes to the source code which work for me (and internally I’ll simply patch-package) and I’ve opened a draft PR in the cucumber-js repo (I’ll update it more tomorrow)
This also covers the use-case that folks have been asking frequently in the cucumber-js issues of running features per worker
Looking forward to hearing your thoughts
*Thread Reply:* > My case is simple, I want to run certain scenarios per specific runners. Sorry as I know it can be annoying, but: why do you want to do that? What happens when you just use parallel normally?
You mentioned the “BeforeFeature” request, I wonder if it’s related to that.
*Thread Reply:* Our use-case is a bit of a specific one, but I'm happy to share 🙂
Our web-app has a layer of authentication with a third party provider, once you login then you select different profiles. The active profile is stored per account (so you can't have 2 profiles in the same account active simultaneously).
Therefore, if I just run parallel what happens is that the tests fail since worker A is using Profile A, then worker B switches to Profile B and so worker A loose the profile mid-test and fails...
From what I saw in the github issues, getting access to the worker information was asked a few times and so I figured I'd make the PR (I'll need to fix the tests but the basic idea is there for discussion).
I wouldn't necessary just pass the worker information but rather all worker/world information but haven't done that yet!
Anyway, if this goes against the structure that you are looking for, that's fine and thank you for reading this/maintaining cucumber-js!
Ps: I have a feeling we are on different timezones, so apologies for the delay in responses!
*Thread Reply:* So your plan is to have each worker create its own profile?
*Thread Reply:* Where/when in your test suite does the login happen? Is it per scenario, or in some kind of global setup?
*Thread Reply:* Heya @matt-SmartBear , It's done inside each feature file, in the background definition https://cucumber.io/docs/gherkin/reference/#background
Example, main-page.feature: ```@WORKER1 Feature: Main Background Given I login in as 'account1'
Scenario: Can see the profiles for choice ...``` Other github issues which I think match the same as I'm asking: https://github.com/cucumber/cucumber-js/issues/2222 https://github.com/cucumber/cucumber-js/issues/2217 https://github.com/cucumber/cucumber-js/issues/1044
If you don't mind me asking, is the parallel implementation in cucumber-js, parallelization or concurrency? I'm seeing that workers sometime idle while the others run, so I'm just making sure if it's my setup
Thank you for looking 🙂
*Thread Reply:* OK, so in your context the problem you want to solve is to not have any two scenarios running simultaneously with the same account profile?
*Thread Reply:* Kinda, yes
I don't want to have two scenarios running the same account and different profiles (each account can choose from multiple profiles but can only have one active at a time)
E.g. Scenario 1 • Mat account ◦ Admin • Scenario 2 ◦ Regular user Once (2) runs, it takes over the profile and (1) fails
Could you please share if you know if the cucumber-js implementation is parallel or concurrent?
With the code changes I did to cucumber-js it does run as I want it but sometimes I can see some workers idling for a bit while the others run. Then they continue later
Hope that was clear and thank you for looking at this
*Thread Reply:* > parallel or concurrent I'm afraid I don't know the difference. Can you explain?
*Thread Reply:* I don’t think it translates neatly to either, but maybe it’s more like parallelism because the workers are independent threads. It’s possible for some of them to be idle if there are fewer scenarios still to be executed than available workers and/or if the setParallelCanAssign logic is constraining what can be assigned.
*Thread Reply:* Reading your explanation, I’m struggling to see why the current functionality couldn’t work for you. If users are the constrained resource, then tag the scenarios with those eg. @User-Matt and then use atMostOnePicklePerTag to ensure that user is only ever logged in from one place at a time. The fact that it might change workers between scenarios shouldn’t matter - you login at the start of each scenario, right? I think your focus on keeping it all on the same worker might be a little misplaced.
*Thread Reply:* You could even do a more custom function based on the combination of user- and profile-related tags if that would make it more efficient. But I don’t think you need to assert which worker.
*Thread Reply:* That's fine, I'll update the PR soon to fix the tests and make it reviewable
You can then decide wether you want it or not, but it should help other folks who've asked for use-cases like this (or at least they can patch-package it if they want)
Thank you for looking at this!
*Thread Reply:* I've updated the tests to the best of my knowledge and removed the draft
If you could share your thoughts there, that would be much appreciated
I can understand if this goes against the maintainers long-term plan, and if that's the case I don't mind at all if this gets closed.
Either way, thank you all for looking and sharing your thoughts 🙏
Hi, is cucumber glue a thing in cucumber-js? I am not clear about what it is and how it works. I couldn't find docs in cucumber-js.
*Thread Reply:* “Glue” generally refers to the code that called by your step definitions that drives your automation. I think the term is used more in the JVM world. So JS has it but just doesn’t call it that - we refer more to “support code”
I'm trying one by badeball but it crashes when ESBuild is used for a preprocessor and locks up with webpack - so both his examples are bogus and I'm ready to look elsewhere.
architecturally there's no such thing as a cypress cucumber library. Cypress is designed to work completely isolated. The one badeball did was essentially just some extra modifications to the cypress code that distilled down the cucumber features into js code. Sadly that "route" is pretty much your only option.
Yeah, I'll pass on that. I'm going to go with straight Cucumber, and since the website is a portfolio I'll rewrite the tests in Cypress as a proof of domain knowledge. Probably do them a 3rd time in Jest. But at the moment I'm hitting the snag of getting Cucumber to cooperate with Typescript. I'm going over the docs on transpiling now.
How the hell do you use cucumber with typescript in a project that isn't a module?
And I can't simply plug type: "module" into the package.json - that breaks nextjs
Partially musing aloud here - I mean no offense to any of the devs or document writers. Once I figure this out I'll be adding my findings to a pull request for the transpling.md file in the docs folder.
K, breaking this down to the foundation with an empty repo running cucumber alone with ts-node. Feature: ```Feature: Addition
Scenario: Basic as it gets
Given I have one
When I add one
Then I have two
And corresponding step def
import { Given, When, Then } from "@cucumber/cucumber"
let accumulate = 0;
Given("I have one", () => {accumulate = 1});
When("I add one", () => {accumulate += 1});
Then("I have two", () => { if (accumulate !== 2) throw "Computer can't add"; });``` Threading further responses (I'm writing this cause I'll need to come back to it to improve the documentation if possible).
*Thread Reply:* I suspect the problem is Nextjs insists that the project be compiled to ESM while at the same time not having the project marked as type="module"; and if I do add that to the package.json file Next.js blows up - so I need to figure out how to do this with Cucumber alone first then approach that hurdle.
*Thread Reply:* And the docs are spot on. So now to bring in the tsconfig directives from nextjs and find the culprit
*Thread Reply:* Solution. NextJS' tsconfig.json.compilerOptions.module directive was set to "esnext" and Cucumber needs it to be "commonjs"
*Thread Reply:* The docs need to mention this somehow. I'll look into a phrasing and make a PR later today on it.
*Thread Reply:* Hi @Michael Morris. I am not fluent in JS, but with many years working around it I am trying to make sense out of it. Just by seeing your message, I hope to get some more understanding about it.
I wanted to use cucumber-js with React app by touching it on sort of a unit level, so not going through a webdriver, but really to write living documentation for business rules of a few complex components. So, I need **.tsx extension for steps, but when extension of file is changed, cucumber-js ignores that file entirely. I struggled to understand the whole thing about modules and transpilers, and one of JS developer wasn’t able to help me, so I decided to give jest-cucumber (https://github.com/bencompton/jest-cucumber) a try.
The result is that it works really great, especially with automatic step binding alternative and it’s incorporated in Jest tests, and testing library or any other tool can be used just out of the box as well, but reporting feature is broken so the point of having a widely accessible documentation is completely missed.
To be honest, I would love to have it all implemented just in cucumber-js but not sure if this is feasible, and did you make it working, or there is a need to request that feature?
This is the example where I cannot make it working for React components within features/support/steps.tsx file:
```import { Given, When, Then } from '@cucumber/cucumber'
...
When('flight summary component is rendered', function () {
render(
<Container>
<FlightSummary flight={flightDetails} />
</Container>
);
});``
Intsconfig.json, module is set toesnext`. I guess it should stay like that in my case, as the application already runs with that setting?
Thanks for reading it!
*Thread Reply:* P.S. I followed instructions in your PR, however, I wasn’t able to make it working for my case using a recipe for ts-node. Still, **.tsx file is being ignored so suggestion to add all steps is provided by cucumber-js.
*Thread Reply:* ts-node doesn't work with tsx files to my knowledge - you'll need to use Babel as the transpiler.
Hi there,
I've been struggling a lot with this - I'm executing the tests using exec() function in nodeJS. It returns the process, which executes the tests.
I want to be able to stop the execution of the tests, but killing the process is not stopping them.
Could someone advise? 🙂
Thanks in advance!
*Thread Reply:* That does seem odd. I’ll see if I can reproduce but might have to come back to you for more information.
*Thread Reply:* Relatedly, since it seems like you’re triggering Cucumber from some code of your own, have you seen the JavaScript API? It doesn’t currently have a way to stop the test run mid-flight but we’re intending to add that soon. https://github.com/cucumber/cucumber-js/blob/main/docs/javascript_api.md
I’d be interested to hear about your use case for running Cucumber from code and wanting to stop the run mid-flight, if that’s something you’d be okay with sharing.
*Thread Reply:* Hi David,
Thanks for your quick response! I'll spend some time and try out the API, I didn't know about it. 🙂 Regarding the stopping of the execution - it's more like I want to be able to stop the test suite execution upon a some signal, not the test itself (because there could be some unexpected behavior, if the test does not finish its work - database interactions, etc.) Since, every test should not be dependent on another, stopping the suite execution should not cause an issue. I'm running the cucumber through the code, because we developed a service, which is responsible for executing the test suites on some remote machines. For example, if the service receives a POST request with some test details, it's going to start the corresponding execution on specific machine. So I want to be able to stop the test suite execution upon a some request to my service.
Hello Cucumbers, I am looking for some clarification and I hope I can find some help over here regarding testing React components on - let’s call it - unit test level so without a webdriver. I have shared more details in this thread: https://cucumberbdd.slack.com/archives/C6QJ6N695/p1677093082738129?thread_ts=1676484576.091459&cid=C6QJ6N695
*Thread Reply:* I'm sorry I'm so late in seeing this - I only check this board once every few weeks or when I'm actively developing. When you transpile modules you have to import the steps using a glob pattern that explicitly mentions their extension. I have typescript set to export as commonJS during testing so this is my cucumber config file for a NextJS site
module.exports = {
default: {
requireModule: ['ts-node/register'],
require: ['features/steps/****/**.ts'],
publishQuiet: true,
exit: true
}
}
*Thread Reply:* You should be able to get it to work by changing the ts above to tsx and using the import directive if you exporting to a module. NextJS isn't happy having the package.json set to module mode for some reason so I had to go with require.
*Thread Reply:* Thanks @Michael Morris! I asked a JavaScript developer some time ago but I didn’t have time to check it out. Indeed, he suggested me to try the following:
> you might be able to use tsc to translate tsx to jsx and then use babel to translate jsx to JS. I will try to sort it out soon, so will get back to you in any case. Hope this can work :fingerscrossed: .
*Thread Reply:* No, if the TSX module is installed Typescript can translate TSX straight to JS.
Hi Team , Im new to Cucumber Can someone please tell me how to share data between steps in one scenario using Cucumber.js, Thanks
*Thread Reply:* https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/world.md
Hi, anyone knows of customizations options for the junit formatter? specifically - can I set the name in the report (currently it is cucumber-js). any other options?
*Thread Reply:* Not currently possible, but something we could look at adding via formatOptions. Would you mind raising a feature request at https://github.com/cucumber/cucumber-js/issues/new/choose
*Thread Reply:* In ruby I know we cannot set the name of the files, but we can set the name of the directory. Not sure if this helps or not @David Goss (I think the filenames are semi fixed, cos of reporter tools upstream).
Hi, What is the maximum thread count I can use in parallel execution, Results are not stable if I use 5 and above..
*Thread Reply:* There’s no technical maximum from Cucumber’s perspective. The limiting factors will be the hardware you run on (the more you do in parallel, the more memory will be consumed by each worker), and the ability of your system under test to handle the parallel activity (shared resources, dependencies between scenarios, etc).
*Thread Reply:* Thanks for your response, I am running the scripts on the docker container hosted in kubernetes cluster, I see only till 4 thread, the results are stable
Hey!
Hope you all are doing good, can you please any of you share with me your experience or any resource that can help me in my case:
I am recently joined cucumberJS club and I need to run the tests in parallel, but i found nothing that could help me
i am using @cucumber/cucumber: 9.0.1
and if it can be enriched with an example to be able to understand it
*Thread Reply:* Have you seen https://github.com/cucumber/cucumber-js/blob/main/docs/parallel.md
*Thread Reply:* Yup, actually i found it after posting the question, but i did not get this part
Guten tag! "Guys" is easily replaced with the more gender-neutral "Folks" or "All". We'd appreciate if you tried to use that. Thanks!
Hi, can cucumber-js allow step definition to be overridden? Here is a user story:
As a tester, I can define a higher priority step definition to override the default step definition, so I can reuse the existing feature tests in multiple projects with the flexibility to extend them when I need.
I saw this for ruby https://makandracards.com/makandra/37067-override-cucumber-steps-without-an-ambiguity-error But not sure if we have a way to do it in js.
*Thread Reply:* There is nothing in the language that prevents this, and further you can actually pull it off in userland since JavaScript allows functions to be overwritten. I'm open to developing this into core if the core team approves, but I need to know a bit more on this - specifically what are the use cases?
What you have to remember is that is a spin-off plugin. Nothing there is official. Even just the notation using end.method is very non-standard.
So in theory you could do the same in js if you wanted?
*Thread Reply:* Have you had the need to reuse a set of feature tests? And allow others to extend the step definitions when they need?
*Thread Reply:* Not really, because you're kind of attacking the problem incorrectly.
*Thread Reply:* Two situations likely will occur. You want a standard cucumber cuke -> Where things like aruba are a massive help
*Thread Reply:* Or you want a situation where you want the "first bit of" cuke 1. Or the "middle bit of" cuke2. In that situation you are incorrectly storing reproducible information in the cuke, where it should live in a class/helper/OO object.
*Thread Reply:* I have a test suite, I need to use it to test multiple projects. However, a few projects have some customisation which makes all tests fail. If I can override one step definition for that project, then it should be fine.
*Thread Reply:* aaaah oki, so you have similar to cucumber. golden features?
*Thread Reply:* so in cucumber, we have a concept known as golden. Which is where we have an input and output, and we put a different "engine" in the middle.
The test is that with the same input, and a different engine, we "should" get the same output.
*Thread Reply:* I can't remember the exact output. But it's on github somewhere.
*Thread Reply:* https://github.com/cucumber/gherkin/tree/main/testdata is one example for gherkin
*Thread Reply:* So
Feature: Inconsistent cell counts
Scenario: minimalistic
Given a data table with inconsistent cell count
| foo | bar |
| boz |
Scenario Outline: minimalistic
Given the <what>
Examples:
| what |
| minimalism | extra
*Thread Reply:* should always produce
{"parseError":{"message":"(6:7): inconsistent cell count within the table","source":{"location":{"column":7,"line":6},"uri":"../testdata/bad/inconsistentcellcount.feature"}}} {"parseError":{"message":"(14:5): inconsistent cell count within the table","source":{"location":{"column":5,"line":14},"uri":"../testdata/bad/inconsistentcellcount.feature"}}}
*Thread Reply:* Let me think...not exactly same situation but kind of...
*Thread Reply:* I can always handle them in a centralised step definition file, by checking what test target is, then handle them differently. But in my case, I am looking for a distributed way to allow it to be handled in each project.
*Thread Reply:* It's like Interface , I want each project can have their own implementation, maybe
*Thread Reply:* But I have a same test scenario, like what your example shows.
*Thread Reply:* yes so you want either screenplay pattern, or you have situation2 where you're not using common helpers/classes
*Thread Reply:* Hi @Tim Yao I am curious why would you need to "reuse and extend" step definitions ? For me they describe a very precise business logic and should in theory be unique per project
*Thread Reply:* reusing step defs is quite common if they're generic ones. Which is what aruba provides users with
*Thread Reply:* ah sorry I thought you were talking about the gherkin itself
*Thread Reply:* @Aleksandar KIRILOV It's actually is reuse feature file...Like the example of the golden feature, I want to reuse it to test multiple projects. The business logic in the test steps are same, but each project may have different implementations for certain steps, and they are agnostic to me.
*Thread Reply:* Each project can have their own step definitions. Those can call common support call to prevent code duplication.
*Thread Reply:* You could also have one common set of step definitions for those steps that do not need redefinition between patterns.
*Thread Reply:* The more you describe the problem, the more it seems this can be steered around.
*Thread Reply:* Thanks, Those can call common support call to prevent code duplication. not sure how to do that @Michael Morris. Can you please give more details?
*Thread Reply:* Given this directory structure
/steps
/project1
/project2
/project3
/common
/support
You could then load the step definitions for project1 with cucumber-js --require /steps/project1/****/**.js --require /steps/common/****/**.js
*Thread Reply:* Then your project step definitions could import from /support and extend those methods or do some config method before calling those methods.
*Thread Reply:* There's a multitude of paths to go through here. Without knowing more specifics I don't know which ones are best.
*Thread Reply:* OK. I got that. It does solve some of the cases. But I can't have one js file for each definition. Using require load way, I can't exclude one step definition from one file which contains other steps I need.
*Thread Reply:* I am also thinking about creating abstraction inside the step definition that may need to be extended. Inside that step definition, use JS to call a function that will load code dynamically which can allow project to override the default code.
*Thread Reply:* require can be invoked multiple times (so can import)
*Thread Reply:* Use your cucumber config file to set up a profile for each project
*Thread Reply:* And have the profile load the definitions needed by that project.
*Thread Reply:* Thanks. Here is what I think is a work around:
As the defacto ruby maintainer, I'd never heard of that. But it seems nice. Not quite sure when you'd use it though
Does someone have a good idea where the chat is for puppeteerjs? I’m trying to type new lines into a text area, and handle.type("first line\nsecond line") isn’t doing it - it just types that text literally. I’ve been searching for hours online, but can’t find an answer.
*Thread Reply:* I’m not aware of a puppeteer community.
Have you tried using a template literal for the input string?
*Thread Reply:* Hmm, that might be needed when using .value, but this problem may be in combination with cucumber - when I manually code handler.type("Foo\nBar"), I do get multiple lines in the text area, but when I use the value that cucumber passes in as an argument, I don’t get any new lines, just literally “Foo\nBar” in the text area. (Example step: Then I type "Foo\nBar"). Is cucumber stringifying the argument first?
*Thread Reply:* I think doc strings is what you need https://cucumber.io/docs/gherkin/reference/
*Thread Reply:* That’ll work in most places for us, but sometimes it needs to be in a table.
*Thread Reply:* It needs to work in a table as well, not just as a doc string. Any ideas?
*Thread Reply:* Hello @plocket just use JS string.replace() to replace your escaped \n by \n - this is mostly code related at this point not gherkin issue imo
*Thread Reply:* ~Thank you. I was having trouble understanding how cucumber was processing the string. I tried to experiment to find out, but kept getting tripped up by the backslashes. How do I make sure to unescape other characters? I’ve been trying to look it up online for a few hours now. The most I could find was~
.replace(/\\{2,}/g, '\\')
~But I experimented with that and it didn’t work at all. I did 'foo\\nbar'.replace(/\\{2,}/g, '\\') in the console and it just came back as 'foo\\nbar' .~
*Thread Reply:* Instead of that, can you point me to where in the cucumberjs code the string is being escaped? That way I can better try to unescape it. I’ll ask on js channels about that.
*Thread Reply:* Is it something like JSON.stringify or is it a Markdown parser?
*Thread Reply:* You may be looking for https://github.com/cucumber/cucumber-expressions
*Thread Reply:* Thanks! Do you know where in there the “stringifying” is going on?
Hey, question: is there any thought if I can print out the console logs along with the reports generated by cucumber?
*Thread Reply:* We use console.log() in our AfterAll() hook and that works fine if that’s what you mean.
*Thread Reply:* it logs all the logs that have been logged during the run and through all steps?
*Thread Reply:* We add those to a string variable as we go and print the whole thing at the end.
*Thread Reply:* That said, if you console log during the tests, that shows up too. I think there is something you can do with the… formatter (?) that can influence the output. Also, we create a file we call a “report.txt” that contains all our logs. [We use that same string that I described.]
*Thread Reply:* you externally created a file for logs and added it to reports, or sth already built-in?
*Thread Reply:* We currently don’t add it to the “published” report. We just add it to our directory and .gitignore it.
*Thread Reply:* and maybe i was not clear in asking my question; what i meant in my question is I need to add the logs to the published report
*Thread Reply:* I think I’ve seen folks talk about something called the formatter. Do other folks know if that’s right? Would that affect the published report? (posting to channel)
*Thread Reply:* There is this.log() which is just shorthand for doing a plain text attachment - not sure if that helps @Shatha
*Thread Reply:* is it something that can help in having all of the logs at the end of the run? or attached in the report folder? and if so, can you help me in how to apply that?
hey champs, i have a question: is there any way to re-run specific step if it has failed for some reason?
*Thread Reply:* I’ve done this by handling the logic internally - I abstract the functions that I define in a Step. Then I catch certain types of errors and call the function again if appropriate.
a step no. Because the concept of a scenario is an enclosed container.
Why would you want to do this. It feels very hacky. The only way I would do this would be using your low-level language. And wrapping the entire thing in a helper.
def run_with_retries(attempts: 1)
begin
# code block
rescue [ErrorsYouThinkMightOccur]
retry if logic_met?
end
end
@Shatha You could also add a tag to the scenario (for example @debug) and call this specific scenario using the -t option (eg., npx cucumber-js -t @debug) In addition you might be able to comment single steps out in Gherkin. But as @luke already hinted this could break expected dependencies between your steps.
Can we access world parameter in Before All Method <#C6QJ6N695|help-cucumber-js>
*Thread Reply:* The doc says it is not possible:
https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/hooks.md#beforeall--afterall
Can you tell us more about your use case ? If you need to access the world inside BeforeAll maybe you are trying to use it in a wrong way
*Thread Reply:* I want to connect to Database and common setup (one time setup in test suite level) in before All method in parallel execution, If i connect to DB in before method , I have to create the data setup for every scenario, Data is creating in runtime, so it cannot interact with the other threads which is running in parallel, so I have to create in before all
*Thread Reply:* Do you need the world object to do such technical things like connecting to a database ? Just put your SQL in a file and load it in the "BeforeAll"
Also imo it is a good practice to have separate dataset for each test - this way you get better isolation and your tests will not leak.
*Thread Reply:* I have different DB env and based on the world parameter env , I want to connect to that DB
*Thread Reply:* It is having application constraint that only one record created for Admin and I want to access the admin account after creating it in one thread
hey, i have a question, is there any way I can ignore packages from being transpiled?
I already have them transpiled and I don’t want them to be transbiled when adding requireModule: ['ts-node/register'],
*Thread Reply:* I think you should create a second tsconfig.json for your test that has the appropriate includes and excludes and then you should specify that ts-node in your tests use that tsconfig. Not exactly sure of the syntax though - sorry
Hi, hopefully someone can help me - When adding a custom formatter, is there any way in the constructor to know if the run is parallel or not? It seems there are no environment variables set at that point and the cucumber options don’t give any clues. Thanks
hey guys, I have 2 steps:
• Then I send a request to Web property api with random property id
• Then I send a request to NA property api with random property id
and a step implemented for these 2 like this:
Then(“I send a request to (NA|Web) property api with random property id”, (api) => {
but when I run it for web, it says:
Step implementation missing for: I send a request to Web property api with random property id
how can I fix it by regex usage, any help is appreciated 🙌
*Thread Reply:* You can read the https://github.com/cucumber/cucumber-expressions#alternative-text
If you need full control then use regex expressions.
PS: Imo you should write your step as follows:
Then I send a request to Web and NA property api ...
Reuse code in your glue and keep your feature files clean and readble.
*Thread Reply:* Also gherkin is about business logic and you seem to be testing some technical APIs - maybe you should take a look at karate
*Thread Reply:* this medium article helped me to fix the issue: https://medium.com/taqtilebr/testing-front-end-applications-with-cucumber-and-cypress-9666771bc8c4
and this step definition is working fine in my case:
Given(/I send a request to (NA|Web) search api/, (api) => {
*Thread Reply:* In cucumber expression, you also can use custom parameter type https://github.com/cucumber/cucumber-expressions#custom-parameter-types But it adds extra code which defines your reusable type, like: ```import { defineParameterType } from '@cucumber/cucumber'
defineParameterType({ name: 'propertyName', regexp: /Web|NA/, transformer: s => s })```
Salutations Earthling! "Guys" is easily replaced with the more gender-neutral "Folks" or "All". We'd appreciate if you tried to use that. Thanks!
Hi there, I hope everyone is doing well. I'm using cucumber-tsflow and I'm getting an error when try to use beforeAll annotation.
I've updated my local using version 4.0.3 and now I can see/import beforeAll/afterAll. However, I'm getting a "binding" error when trying to use context injection and beforeAll decorator. If I use before decorator, everything works fine.
Here is how I'm using it: ```@binding([Login, Client]) class HookSteps { constructor(protected login: Login, public client: Client) { } @beforeAll() public async beforeAll(): { await this.login.LogIn() await this.client.Client(this.login) ... } }
Here is the error that I'm getting:
```VError: a BeforeAll hook errored, process exiting: tests\functional\features\support\hooks.ts: Cannot read property 'LogIn' of undefined
at Runtime.runTestRunHooks (c:\project\code\myapi\node_modules\@cucumber\cucumber\src\runtime\run_test_run_hooks.ts:32:19)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Runtime.start (c:\project\code\myapi\node_modules\@cucumber\cucumber\src\runtime\index.ts:103:5)
at async runCucumber (c:\project\code\myapi\node_modules\@cucumber\cucumber\src\api\run_cucumber.ts:125:19)
at async Cli.run (c:\project\code\myapi\node_modules\@cucumber\cucumber\src\cli\index.ts:78:25)
at async Object.run [as default] (c:\project\code\myapi\node_modules\@cucumber\cucumber\src\cli\run.ts:38:14)
caused by: TypeError: Cannot read property 'LogIn' of undefined
at Object.BeforeAll (c:\project\code\myapi\test\functional\features\support\hooks.ts:17:22)
at globalBindFunc (c:\project\code\myapi\node_modules\cucumber_tsflow\src\binding_decorator.ts:256:48)
at Object.run (c:\project\code\myapi\node_modules\@cucumber\cucumber\src\user_code_runner.ts:37:21)
at Runtime.runTestRunHooks (c:\project\code\myapi\node_modules\@cucumber\cucumber\src\runtime\run_test_run_hooks.ts:21:50)
at Runtime.start (c:\project\code\myapi\node_modules\@cucumber\cucumber\src\runtime\index.ts:103:16)
at runCucumber (c:\project\code\myapi\node_modules\@cucumber\cucumber\src\api\run_cucumber.ts:125:33)
at async Cli.run (c:\project\code\myapi\node_modules\@cucumber\cucumber\src\cli\index.ts:78:25)
at async Object.run [as default] (c:\project\code\myapi\node_modules\@cucumber\cucumber\src\cli\run.ts:38:14)
Any thoughts on that?
beforeAll doesn't have a world object. That might be where the issue comes from.
Okay, by design as I could read here https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/hooks.md#beforeall--afterall
Sorry missed this. Yes deliberately. There are some ways in some languages to get some sort of configuration instance, but by and large it doesn't make sense as the world is inherently tied to running tests, which beforeall/afterall aren't quite yet doing.
How can I do an unique login for all scenarios? I have over 2000 scenarios... it is doing new login for each of them... that's why I would like to add this into beforeAll
so if you want to login for each scenario you simply place that in your before hook.
That's what I have now... logging in for each scenario, but I want to logging in just once, and the credentials can be used for all scenarios
*Thread Reply:* Something like this? ```let username; let password;
BeforeAll(function () { username = random(); password = random(); });
Then(...() { loginwith( username, password ); });```
*Thread Reply:* From what I just read about BeforeAll when running in parallel (just below this), this solution won’t work if you’re running tests in parallel. Maybe you’d define them right at the start:
let username = random();
let password = random();
Hey, I have a question: how can I run “BeforeAll” once - at the beginning of the class and not to be running many times in parallel - since i am enabling the “parallel”
*Thread Reply:* I haven't used parallel testing but I think there is a variable set in the process.env that tells you the executor ID. You might use that to do something like
if(process.env["CUCUMBERWORKERID"] === 1)
*Thread Reply:* Can you tell us what is your use case why do you need it to run only once ?
*Thread Reply:* so i am building api tests and i need before running the tests to create users per supported countries to be used in my test
*Thread Reply:* > if(process.env["CUCUMBERWORKERID"] === 1) this one to be set in beforeAll right
*Thread Reply:* https://github.com/cucumber/cucumber-js/blob/main/docs/parallel.md
*Thread Reply:* just before you go: as a best practice each test should have it's own data set and cleaned at the end to avoid leaking so what you are doing is a bit a "quick and dirty"
*Thread Reply:* IMO each test should create the user in the BeforeAll and in AfterAll should clean them
*Thread Reply:* this will slow down a bit your tests but will make them more stable
*Thread Reply:* but the thing in my case, there is no value of creating new users for each test because i am creating them for the sake of testing the API, that does no write or modifications
*Thread Reply:* Instead of doing this instead you should be using a more model based approach. I've done this in my last few jobs and I'm going to make a gem based off this I think going forward
Your tests should be doing something like
Given usertype A
This then does a findorcreate by "logic"
*Thread Reply:* Hmm, did not get your point fully mind sharing an example!
*Thread Reply:* ```Scenario: A user who likes apples can look at a shopping list Given a user who is an apple fan Then they are able to open the shopping list
Given('a user who is an apple fan') do # logic to find or create a user who is an apple fan end```
*Thread Reply:* There is a open issue https://github.com/cucumber/cucumber-js/issues/1153
*Thread Reply:* PR but no progress https://github.com/cucumber/cucumber-js/pull/2140
*Thread Reply:* My workaround is use another script to run the required test condition setup before I run the cucumber-js testing. I pipelined them in CI. I think it's also easy to setup in npm script as well.
*Thread Reply:* it would be something like (Say in jenkins)
```stage('prior setup') { steps { sh 'run your step here' } }
stage('cucumber') { steps { sh 'bundle exec cucumber' } }```
*Thread Reply:* @Tim Yao I assume you're the same person from the issue/PR. But in essence I've marked the issue as won't fix, and I advise the PR to go the same route. It's solving a problem that in essence isn't broken in my eyes. But I'll let other people maybe provide more input. You've even articulated here a better solution which I wholeheartedly agree with.
I appreciate you may have spent some time on the original PR, and as such won't close that (Plus I'm no JS expert). But either way it's great to see you contributing and please don't stop on my behalf.
*Thread Reply:* Issue resolved by upgrading selenium Webdriver and geckodriver
This is a selenium issue @Chandrika not cucumber. (Or WDIO perhaps from the name of your stuff).
My users provide their services in different languages to increase accessibility to vulnerable populations who don’t have good support right now. Sometimes they have 5 languages and hope to add more. They need to be able to test each language separately, so each language can fail separately - each translation could introduce changes in the code (yeah, it sucks, but life’s not perfect and we’re stuck with it). If they have 10 tests and 5 languages, that means writing and maintaining 50 tests, which is a bit much.
Do folks have ideas for how to automate this? They can set the languages in a Background or something, or even in env vars, but I’m not sure what to do with them at that point. A reply in a thread would be most helpful, thank you.
*Thread Reply:* I’m not sure about if I can understand the problem: do you have to provide Gherkin Scenarios in different languages or does your application support multiple languages or do you have to test your application for multi-language environments (eg., browsers, OS’s)?
*Thread Reply:* The applications support multiple languages and each language needs to be tested independently, @Matthias Carell. Without some special behavior, each language would need its own Gherkin Scenarios that were otherwise identical to those of the other languages. Does that make more sense?
*Thread Reply:* I see. I think I would use data tables like this: ```Given the user has set the app language to <language_name> And the cancel button shows the corresponding label | lang | label | | en | cancel | | de | Abbruch | When the user clicks on the button Then a message confirms this action | lang | label | | en | Action canceled | | de | Aktion abgebrochen |
Examples: multi language cancellation | language | language_name | | en | English | | de | German |``` This way you can use the same scenario for multiple languages. The Examples section (Outline table) would repeat the scenario for each language while the steps with data tables could pick the actual language setting accordingly.
*Thread Reply:* Wow, I wasn’t aware of Examples. I’ll have to look at how they work. Still some extra work to run languages only conditionally, but we can handle that other ways. I’ll look into this and see if it suits our purposes!
*Thread Reply:* Examples: are part of Scenario Outlines as described here https://cucumber.io/docs/gherkin/reference/#scenario-outline Newer versions of Cucumber do recognize Examples: without starting the scenario with Scenario Outline:
*Thread Reply:* Regarding how to run only selected languages please look at https://cucumber.io/docs/cucumber/api/?lang=javascript#tags You will find an example that have multiple example tables for a single outline scenario. This allows you to add tags to each example table like this: ```Scenario Outline: show feedback on cancel action Given the user has set the app language to <language_name> And the cancel button shows the corresponding label | lang | label | | en | cancel | | de | Abbruch | When the user clicks on the button Then a message confirms this action | lang | label | | en | Action canceled | | de | Aktion abgebrochen |
@langen Examples: cancellation in english | language | languagename | | en | English |
@langde Examples: cancellation in german | language | languagename | | de | German |``` Now you can use tags to run scenarios only for a selection of all available languages.
*Thread Reply:* Thanks, this is a really strong lead and I’ll look into it! I must say there were no docs on cucumberjs about this capability existing in cucumberjs. Is there a doc that describes either that cucumberjs always has the same capabilities as cucumber? Or that lists which features it has implemented so far?
*Thread Reply:* When I say Cucumber I don’t have a specific version in my mind. The docs from cucumber.io/docs should match with the current version of cucumberjs If a feature is language specific the page offers you a filter to show the doc related to the right language:
*Thread Reply:* However most Cucumber versions should support most aspects of the Gherkin language. I would expect all more mature versions (eg. cucumberjs or cucumber for Java) to support scenario outlines. If you want to learn more I would recommend Writing Great Specifications. I learned a lot from this book.
*Thread Reply:* I built a test suite that had multiple language support - 12 of them. The language to be tested was passed as a world parameter. Gherkin steps did not refer to the exact text that would be appearing nor should they - they aren't supposed to contain details that small.
*Thread Reply:* Yes, I agree Gherkin steps should avoid referring to the exact text. We’re making the steps language agnostic generally. The only reason that we need to test with every language is to make sure that the translators don’t mess up the code. That is, we won’t need the tables that check for words from the different languages, though I do appreciate you providing those in the example.
We do have a weird use case, and languages is only one reason, so that we can support vulnerable users. If you ever want to get into it, let me know ;)
*Thread Reply:* That said, our internal tests to make sure we’re handling languages properly will definitely use the example tables you showed to look for phrases so that we can be sure we’re actually testing languages correctly.
*Thread Reply:* ~Quick question: Can the example tables have multiple rows? I’m not sure why you split those rows into separate tables.~ I think I understand - they have different tags.
*Thread Reply:* Are you sure you're not reinventing the wheel? The implementation my team used put all the translations into a json file structured something like this:
{
"color": {
"US": "color",
"UK": "colour",
"other": "color"
}
}
*Thread Reply:* Each major language has a file, and regional variation is covered by the nation codes as seen above.
*Thread Reply:* The test steps can refer to the translation by their key.
*Thread Reply:* The tests then load the same language file the code under test is using. If the code is working correctly it should provide a match.
*Thread Reply:* Javascript has multiple i18n implementations. I wouldn't recommend inventing yet another one - do some research, find an existing solution you like and save yourself a headache.
*Thread Reply:* I can’t control how the translation is arranged. As I said in the original post, it sucks, but life isn’t perfect and that’s what we’ve got.
*Thread Reply:* The code under test should be arriving at it using some process similar to the above. If not sourced from a json file perhaps sourced from an API endpoint?
*Thread Reply:* Whichever is used the testing code should independently fetch the value from the source, then verify the code under test is displaying it.
*Thread Reply:* Each translation string almost certainly has an identifying key. I've never seen a translation system that didn't do this.
*Thread Reply:* Does it matter how the language is being triggered? The end to end test goes to the url for the appropriate language. It’s in the url args.
*Thread Reply:* If you want to discuss the translation situation, maybe we can DM about that?
*Thread Reply:* It shouldn't matter how the language is triggered so long as the testing code has access to the translation strings.
*Thread Reply:* And I'll be happy to take a few DM's. Since I'm between jobs I've got the free time.
*Thread Reply:* if the scenarios proper can be written in english, I would write the scenarios once without outlines, then use a config tool to pass in your dynamic language. It makes writing tests 10x easier.
*Thread Reply:* Use things like hash lookups or yml files to store your i18n translations.
*Thread Reply:* Unless you explicitly want the translations visible in your report.
*Thread Reply:* That sounds like an interesting alternative, @luke, but I’m not quite understanding. Why do I need a scenario outline if I’m not going to use Examples? How/where would I use the config values? Can you give me a small example?
*Thread Reply:* you would write one scenario for each use case, and use i18n to translate
*Thread Reply:* You can then feed in the translation either as a cucumber step or an env var step. Easy-peasy
*Thread Reply:* Not sure how I can make that kind of Step that wouldn’t require writing a test for each language. If I use env vars, I’m not sure how I’d make sure each language had its own unique test.
*Thread Reply:* Because you just lean on the env var in your step/support code and use i18n, it's literally designed for this.
*Thread Reply:* So you either have a given step, or an env var (Which you could set in a step or as a pre-req)
*Thread Reply:* ```Given('The website is in English') do I18n.locale = :en end
Given('The website is in Norwegian') do I18n.locale = :nb end
Then('I am welcomed to the homepage') do expect(@app.home.welcomemessage).to eq(I18n.t('home.welcomemessage')) end```
*Thread Reply:* or for env var you do something like
LANG=en cucucumber
LANG=nb cucumber
*Thread Reply:* What does the single Scenario look like that will run a test for each of English and Norwegian?
*Thread Reply:* ```Feature: Run test Scenario Outline: Validate homepage message Given the website is in <language> And I am on the homepage Then I am welcomed to the homepage
Examples:
| language |
| English |
| Norwegian |```
*Thread Reply:* if you want to use env vars, then it depends if you want them in a step or not.
*Thread Reply:* if you use env vars without steps then it would not have the outline
*Thread Reply:* I think I’m trying to say that I don’t know how I’d do separate tests if I wanted to use env vars.
*Thread Reply:* Feature: Run test
Scenario Outline: Validate homepage message
Given I am on the homepage
Then I am welcomed to the homepage
*Thread Reply:* Yes, and LANG=nb cucumber, but what’s the rest of the code?
*Thread Reply:* so in your env.rb you would set the locale from the env var
*Thread Reply:* Though I’m not sure how you can test both languages at the same time like that.
*Thread Reply:* I don't know your business case. Maybe some tests only are valid in one language, and you don't want to tag your tests as @not_nb e.t.c.
*Thread Reply:* you could then have tasks that ran 1/multiple languages as a single script
*Thread Reply:* ```# commoneuropeanlanguages.sh
echo 'Running english' LANG=en cucumber sleep 1 echo 'Running swedish' LANG=sv cucumber sleep 1 echo 'Running french' LANG=fr cucumber sleep 1```
*Thread Reply:* stages {
stage('Run common languages') {
sh('./common_european_languages.sh')
}
}
*Thread Reply:* Happy to help.
In short, one of two ways will help (IF you don't need the verbose translations visible to your report recipients).
Way 1 - Use env vars, inject them in - preferably silently, run your tests for 1 language Way 2 - create gherkin steps to pivot / switch languages, useful if your tests need to flit and flot between 1/2/3/4/5 languages per scenario / rule e.t.c.
*Thread Reply:* And above all else, please lean on i18n if at all possible 😄 it's literally designed for this exact purpose
Hello there,
I have been utilizing cucumber-js for quite some time now. However, recently, while running the tests, we encountered a TypeScript issue that caused the test startup to fail. The problem was that cucumber didn't start running, and no tests were executed. Surprisingly, the test didn't fail the pipeline and exited with status 0.
Is there any way to configure cucumber to fail if no features/scenarios are executed during the test run?
*Thread Reply:* Hello, I would suggest to wrap your tests in a JS file and use the cucumber-js API to run your tests and add some logic that evaluates the number of steps ran and calls "process.exit(code)"
*Thread Reply:* https://github.com/cucumber/cucumber-js/blob/main/docs/javascript_api.md
*Thread Reply:* An expected scenarios count as a cli argument isn't a bad idea though.
*Thread Reply:* @Michael Morris or atleast "bigger than zero". Maybe we should open an issue in github ?
*Thread Reply:* @luke please read the full conversation - if missconfigured, cucumberjs can report that everything is OK when infact your tests are not ran at all. It will not alter any existing functionalities to add a simple --fail-on-no-tests parameter
*Thread Reply:* I have done. If the startup is wrong / faulty, cucumber doesn't know this. Again 0 tests being ran - irrespective of why, isn't an issue.
*Thread Reply:* If the tests "failed" to run, then that's a different situation.
*Thread Reply:* @luke sorry my friend. Ok then maybe wrapping the test run in a bash or js script can provide the additional logic that OP needs.
*Thread Reply:* Yeh, I'm not sure readily how easy that is to do / why you'd want to do that, but each to their own.
One way you can do it in ruby (I'm not sure if this exists in other languages), is the concept of a dry run
*Thread Reply:* @luke It is not an expected result for the CI to have 0 tests run. I am not recommending that it always fails, but rather suggesting that a flag be added. This flag would indicate that if 0 tests are run, the expectation is for the run to fail.
*Thread Reply:* Sorry, that's just not the case, I'm not sure why you're thinking this. A simple use case would be
@not_used
Feature: Abc
Scenario: Def
cucumber -t @abc
*Thread Reply:* ```[17:25:53] luke@luke-ubuntu:~/Code/exordo-app-automation$ cucumber -t @abc 2023-06-28 11:21:10 - INFO - Automation Helpers - Adding patch: AutomationHelpers::Patches::SeleniumLogger 2023-06-28 11:21:10 - DEBUG - Automation Helpers - When using the Selenium Logger that is set to pipe to a file, the Net::HTTP adapter (default), can return unencoded binary (confusingly called ASCII-8BIT in Ruby). Consequently we set the logger to binmode so it doesn't try to encode the data - this would always cause errors for non-ASCII characters, whatever the parent encoding is. An example of this is ©.
See https://github.com/ruby/net-http/issues/14 for a root cause analysis of the Adapter
2023-06-28 11:21:10 - INFO - Automation Helpers - Patch successfully added.
0 scenarios 0 steps 0m0.000s```
*Thread Reply:* [11:21:10] luke@luke-ubuntu:~/Code/exordo-app-automation$ echo $?
0
*Thread Reply:* This would fall into the "not-cucumber" pot. If you want to fail based on the number of scenarios ran, that's fine. But it's not something that should be happening by the design of cucumber.
*Thread Reply:* ```# env.rb
require 'dotenv' Dotenv.load('.env')
yapowwwww```
*Thread Reply:* cucumber -t @abc
undefined local variable or method `yapowwwww' for main:Object (NameError)
/home/luke/Code/exordo-app-automation/features/support/env.rb:6:in `<top (required)>'
<internal:/usr/share/rvm/rubies/ruby-3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
<internal:/usr/share/rvm/rubies/ruby-3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
/usr/share/rvm/gems/ruby-3.2.1/gems/cucumber-8.0.0/lib/cucumber/glue/registry_and_more.rb:123:in `load_code_file'
/usr/share/rvm/gems/ruby-3.2.1/gems/cucumber-8.0.0/lib/cucumber/runtime/support_code.rb:145:in `load_file'
/usr/share/rvm/gems/ruby-3.2.1/gems/cucumber-8.0.0/lib/cucumber/runtime/support_code.rb:82:in `block in load_files!'
/usr/share/rvm/gems/ruby-3.2.1/gems/cucumber-8.0.0/lib/cucumber/runtime/support_code.rb:81:in `each'
/usr/share/rvm/gems/ruby-3.2.1/gems/cucumber-8.0.0/lib/cucumber/runtime/support_code.rb:81:in `load_files!'
/usr/share/rvm/gems/ruby-3.2.1/gems/cucumber-8.0.0/lib/cucumber/runtime.rb:274:in `load_step_definitions'
/usr/share/rvm/gems/ruby-3.2.1/gems/cucumber-8.0.0/lib/cucumber/runtime.rb:74:in `run!'
/usr/share/rvm/gems/ruby-3.2.1/gems/cucumber-8.0.0/lib/cucumber/cli/main.rb:29:in `execute!'
/usr/share/rvm/gems/ruby-3.2.1/gems/cucumber-8.0.0/bin/cucumber:9:in `<top (required)>'
/usr/share/rvm/gems/ruby-3.2.1/bin/cucumber:25:in `load'
/usr/share/rvm/gems/ruby-3.2.1/bin/cucumber:25:in `<main>'
/usr/share/rvm/gems/ruby-3.2.1/bin/ruby_executable_hooks:22:in `eval'
/usr/share/rvm/gems/ruby-3.2.1/bin/ruby_executable_hooks:22:in `<main>'
*Thread Reply:* [11:24:32] luke@luke-ubuntu:~/Code/exordo-app-automation$ echo $?
2
*Thread Reply:* Hopefully that clarifies everything for you 😄 But yeh if you want to write some shell wrapper that queries the amount of ran scenarios, that's all well and good. There is a gem called cuke_modeler that will give you those stats. maybe something similar exists in JS or can be written readily?
*Thread Reply:* @luke In normal circumstances, I expect it to behave as it is currently doing. However, if I pass the appropriate flag, I would prefer it would fail fail.
*Thread Reply:* what is the exit code from that command? I would expect it to be exiting with 0.
*Thread Reply:* But it actually failed becuse nothing ran even though It should have about 50 test runing
*Thread Reply:* @luke What I meant was adding a CLI arg
cucumber-js --expected-scenarios 20
If the number of passes doesn't match the argument, exit code 1. And yeah, you can do this with a wrapper but it isn't straight forward.
*Thread Reply:* @Michael Morris i think the better solution for me is --minimum-tests 1
*Thread Reply:* Maybe just --expect-tests and if that flag is present fail if nothing runs.
*Thread Reply:* Hello I have opened an issue "feature request" in cucumber github
https://github.com/cucumber/cucumber-js/issues/2296
*Thread Reply:* @Aleksandar KIRILOV amazing, thank you...
*Thread Reply:* @Michael Morris I understand what you meant, but I've said several times now this isn't something that should be determined by cucumber.
I tried to do the following: ```Background: @tag Examples: | a | b | | c | d | | e | f |
Scenario: a scenario Given <a> and <b>``` I got parsing errors. Is there another way to create the same examples for multiple scenarios? An answer in the thread would be great.
*Thread Reply:* Background steps are added to all scenarios in the same feature. So the tag would apply to all scenarios. Therefore I don’t think it would make sense to have tags in the background section. Regarding the outline / examples tables I don’t think this is available on feature level. As discussed in the thread before you might be wetter with the setting the language in the configuration and run tests with one configuration per language.
*Thread Reply:* the parser error will tell you the problem, likely here an invalid keyword
*Thread Reply:* Thanks for the input. I’ve tried with the configuration, but I can’t get it to do what I want. What the users want to be able to do:
• By default, only the default language will be run.
• Users would be able to manually trigger running the same separate individual tests for each of multiple languages.
• Users would be able to manually trigger just one language.
I’m not sure how to achieve the second of those objectives using the configuration file since without Examples, a Scenario can only be triggered once. Any ideas?
*Thread Reply:* If you want to dynamically (but not at runtime), configure the tests to be ran multiple times, that's not something you "should" do with cucumber or any testing framework, as it breaks TIL.
*Thread Reply:* you should design it as I mentioned, using i18n, and passing the key in as an env var
*Thread Reply:* you can then also (in your env), do something like
ENV.fetch('LANG, 'en')
*Thread Reply:* so you don't need to pass in a language, it'll just default to en
*Thread Reply:* I can’t find the definition for TIL, but I think I understand what you mean by it - no default repeated input or something like that. Doesn’t that mean Background breaks TIL, though? Isn’t that for Steps and such that are supposed to be repeatable for all tests in a Feature?
*Thread Reply:* Sorry TIL or TIP is test isolation law/principle. which states tests should be independent.
*Thread Reply:* you shouldnt have 1 test that does 2 things, it should be 2 tests.
*Thread Reply:* background and examples are just examples of DRYing, they don't repeat things inside a single test.
*Thread Reply:* Just simply do something like I said earlier
Feature: Language test
Scenario: Welcome message
Given I am on the homepage
Then I am welcomed home
*Thread Reply:* Then why is using the same Examples for every test TIL? Sorry, trying to understand the differentiation. And maybe I haven’t described my use case very well.
*Thread Reply:* I'm not sure what you're complaining about. Like what is the issue.
*Thread Reply:* i've told you the two ways you should architect the thing. Until you go away and build one of those two options, try not to focus on complaints.
*Thread Reply:* Sorry, not trying to complain, just to understand and develop. I’ve tried the configuration methods, but they don’t fulfill the requirements. Maybe I’m doing that wrong, but if so I haven’t yet understood the right way to do it. If so, I apologize if I’m missing something that seems obvious. I’m not sure how else to describe my issue, though, but I’ll try again:
n times longer, where n is the number of languages they’re translating. [In some cases, that can take hours.] Just after translation, the uses want to be able to test multiple translations in one go or a single language at a time. They want to run them as separate tests so they can isolate which translation has a mistake in it.
Does that help at all? Sorry if I’ve repeated stuff you’re already clear on, I’m just not understanding how the given configuration methods can help fulfill the requirements I’m describing.*Thread Reply:* From what I can tell, using the configuration methods described, I can allow users to test one language per test run. Because of Reasons that are equally as frustrating, if not more frustrating, than the translation method, users would have to wait for each test suite to finish before triggering the next one as opposed to just triggering them all at once. It’s a lot of babysitting for 5+ languages. If I have to, I’ll make users do that, but that’s not the ideal choice.
*Thread Reply:* Again, because of the Reasons, users will have to run each set of language tests in series if they’re running them using the configuration method. Or at least, I can’t see a way to avoid it. When the users are running the tests in GitHub, each time the action runs, the tests have to run their setup. Each time the tests run their set up, no other tests can be running at the same time.
*Thread Reply:* Maybe there’s something I’m not understanding about how to use the configuration and still avoid that.
*Thread Reply:* I’m lost now. Just speak to your QA lead or something and have them figure this out. I’ve literally given you most of the solution
*Thread Reply:* I’m the whole development team. Sorry to have frustrated you. Just so I understand, do you feel the configuration methods cover the requirements? Have I missed how the configuration methods work?
*Thread Reply:* I’ve given you both options for solving the prob using a translation file. And if you need to be verbose you already have the soln
*Thread Reply:* Maybe if I explain what I’ve understood about the configuration methods.
*Thread Reply:* User sets an env var to the language. LANG=es. They run the tests once with that language. They then set the env var to a different language. LANG=nb. They run the tests again with the new language. Is that correct?
*Thread Reply:* How they set it is irrelevant. Just that it is set using an env key.
*Thread Reply:* Write a shell loop or pass in a bar that is comma separated and unchain it
*Thread Reply:* Wow, loop in the shell instead. That could work I think. I can at least try it. I’m not sure what a bar is, but I don’t think I should unchain it (right?), so I probably want to skip that option anyway. Anyway, I can look up a bar.
*Thread Reply:* then ```# loop_cucumber.sh
languages=$(echo $LANG | tr "," "\n")
for locale in $languages do LANG=locale cucumber done```
If the config has tags defined and the cli also uses tags, what tags does cucumberjs use? Use the thread to answer if you can.
Hi there,
I'm running cucumber js (with playwright) on a relatively slow machine (which I can't change). When we run the testing, it runs for a few minutes without any output and then right at the end spits out the output / results of testing. This can take over 4 minutes sometimes. Is there a way to print / output whats happening as the testing is proceeding. perhaps a verbose output of the steps being performed? or am I perhaps approaching this the wrong way?
*Thread Reply:* You might consider giving the pretty formatter a try https://github.com/cucumber/cucumber-js-pretty-formatter
*Thread Reply:* That worked a treat, exactly what I needed 🙂
After 7 months I'm still without work. Does anyone know of a company that could use someone familiar with cucumber-js and related technologies?
I am new to cucumber and NodeJs both...Trying to understand how the cucumber test flow works
any link which explain how the cucumber workflow happens ? Any article/video on how excalty the cucumber thing works ?
*Thread Reply:* I am not sure if I understand correctly the answer but if you want to know how cucumber(js) works you should look at source code.
A good start might be in cli.run() function
https://github.com/cucumber/cucumber-js/blob/main/src/cli/index.ts#L41
Also the gherkin language's model diagram will help you understand how things work
*Thread Reply:* We could go really deep on this.
What problem are you trying to solve?
*Thread Reply:* I was looking for connection between feature files and the step.js files...
*Thread Reply:* In this section of the intro docs, it describes how to get started. It gives an example of code in steps.js. The feature files use the sentences that you create in your steps.js.
Another question - where should I enable DEBUG=cucumber so that I can see debug log getting printed ?
Hi, guys, while using cucumber.js parallel workers, is there a way to assign different custom environment variables to different workers. i.e. I need to assign different BASE_URL env vars to different parallel workers
*Thread Reply:* Hello @Terence Tian, there is a variable called CUCUMBERWORKERID that is set to 0, 1, 2 etc helping you distinguish your workers.
From thereon my advice would be to have different .env (ex: .env.0, env.1) files for each worker that has a set of different URLs and other needed configs.
You can load your dotenvs with something like:
require('dotenv').config({ path: `.env.${process.env.CUCUMBER_WORKER_ID}` })
https://github.com/cucumber/cucumber-js/blob/main/docs/parallel.md
*Thread Reply:* @Aleksandar KIRILOV thanks for the advice, I end up using spawn in child_process to distribute work and env variables to different workers to run cucumber.js command
Hello, I have two queries 1) I am trying to enable debug logs but DEBUG=cucumber is not working. Please suggest If any other method. 2) How to run selective test cases ? like out of 5 feature file I want to run only first two
*Thread Reply:* For item 2, I think you can use tags on feature files and use tag expressions to only test those features.
*Thread Reply:* Re running a subset of scenarios, you have a few options including tags as mentioned above https://github.com/cucumber/cucumber-js/blob/main/docs/filtering.md
A question about getting the cucumber.io published report URL. I see the published report URL is part of the pre-formatted message returned from the service. In https://github.com/cucumber/cucumber-js/blob/2fd424aa7127a6449291015ad326f555ed957203/src/publish/publish_plugin.ts#L30C6-L30C6 For some reason, I would like to send this URL to other CI tasks instead of letting it stay inside the console(which is hard to access). I can easily extract the URL from the pre-formatted message by using regex but how can I access the publish output? Can I get it from afterall hooks? I can patch the code or submit a PR if you like.
*Thread Reply:* There’s no way to capture the publish message unfortunately. Probably the best thing would be to direct stderr output to a file when you run, and then have another build step that parses it from that file.
*Thread Reply:* For context, the future of the Reports service is uncertain and we’re not currently making any changes around it. If you can get by with the html formatter (which has roughly the same outut) then I’d probably recommend that.
*Thread Reply:* emm, I understand the returned message is out of the control of cucumber-js. Looks like the only option is patch by myself and grab the url for now.
*Thread Reply:* The stderr output is too big which is hard to parse. and html formatter is what we are using but we are migrating to GitHub actions that doesn't have a good storage solution for it. Instead of setup my own file storage in cloud, I feel the cucumber.io report is simple.
Hey, I'm trying to use cucumberJS in typescript and incorporate clet to test an interactive cli. When the module is added I get an error saying require() of ES module <path> is not supported, instead change the require of runner.js in <path> to a dynamic import() which is available in all CommonJS modules which suggests that I should be using import instead of require to import clet.runner but I am already using import in this case import { runner } from 'clet';. Any ideas on what the problem is here?
*Thread Reply:* You might be using import syntax in your TypeScript, but when it’s compiled down to JavaScript by default it is transformed to require syntax. You can change this in your tsconfig.json in the compilerOptions though.
*Thread Reply:* Feel free to pop your config in here and I can sanity check. It’s somewhat tricky to get right, and the picture is complicated by the import vs require thing.
*Thread Reply:* Ok thats probably the issue, here is the config
{
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"strict": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"allowJs": true,
"esModuleInterop": true
}
}
*Thread Reply:* I meant your cucumber config, but yeah the ‘module’ option will need to change to something like ‘esnext’
Is there a puppeteer Slack or Discord somewhere? Would it be inappropriate to ask puppeteer questions in here? I’ve gotten the impression that a fair number of people that use cucumber use puppeteer as well. An answer in a thread would be great.
*Thread Reply:* Issue fixed with Process.env[NODETLSREJECT_UNAUTHORISED”]=0
I’ve been running my tests successfully. I changed some code that doesn’t affect this test at all (I know, I know, but all the other 30+ tests are passing and the difference in this test definitely doesn’t have anything different in the Before) and suddenly a test is failing because of the Before(). The output is printing undefined right after the x Before. I moved the code in there into its own async function and called that in Before() with an await, but that hasn’t given me any more specific message or line numbers. I’ve wrapped the Before() in a try/catch, but it’s not catching anything. Here’s what I’m getting from the output:
```1) Scenario: My test # test.feature:line
✖ Before # steps.js:line
undefined
✔ Given I start the test # steps.js:line
✔ And another step # steps.js:line
✔ And another step # steps.js:line
✔ And another step # steps.js:line
✔ After # steps.js:line
1 scenario (1 failed) 4 steps (4 passed) 0m17.605s (executing steps: 0m17.496s) /Users/repo/node_modules/indent-string/index.js:11 throw new TypeError( ^
TypeError: Expected input to be a string, got undefined
at module.exports (/Users/repo/nodemodules/indent-string/index.js:11:9)
at formatStep (/Users/repo/nodemodules/@cucumber/cucumber/lib/formatter/helpers/testcaseattemptformatter.js:87:48)
at /Users/repo/nodemodules/@cucumber/cucumber/lib/formatter/helpers/testcaseattemptformatter.js:101:17
at Array.forEach (<anonymous>)
at formatTestCaseAttempt (/Users/repo/nodemodules/@cucumber/cucumber/lib/formatter/helpers/testcaseattemptformatter.js💯22)
at formatIssue (/Users/repo/nodemodules/@cucumber/cucumber/lib/formatter/helpers/issuehelpers.js:25:94)
at /Users/repo/nodemodules/@cucumber/cucumber/lib/formatter/summaryformatter.js:55:48
at Array.forEach (<anonymous>)
at SummaryFormatter.logIssues (/Users/repo/nodemodules/@cucumber/cucumber/lib/formatter/summaryformatter.js:54:16)
at SummaryFormatter.logSummary (/Users/repo/nodemodules/@cucumber/cucumber/lib/formatter/summary_formatter.js:41:18)
Node.js v18.17.0``` How can I figure out what’s going on? An answer in a thread would be much appreciated.
*Thread Reply:* Thank you, your reply was very helpful. [For the People of the Future, the problem was that I was trying to manipulate values in the callback argument in After() , scenario.result.status. Shouldn’t be doing that.]
*Thread Reply:* Is it possible to manipulate the willBeRetried value in the options that are given to the After() callback, or should we avoid that too? It would be incredibly useful for us if we can choose dynamically whether to rerun the test or not.
*Thread Reply:* Same problem really, that should be immutable. I think finer-grained control of retries is an interesting use case though, feel free to raise an issue on there. It might be something we could look at with the new plugins concept.
What is the second argument to the After() hook callback? The docs are here: https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/api_reference.md#afteroptions-fn. They say “When using the asynchronous callback interface, have one final argument for the callback function.” That doesn’t quite describe how cucumberjs will use last argument.
*Thread Reply:* This comment in GitHub shows a function being handed in as an argument to which you can pass, among other things, the status of the test. Is that the second argument? What are the other arguments that are possible to hand in? Or is that an old API that doesn’t exist anymore? One example given:
After((world, callback) => {
callback(null, 'skipped');
});
*Thread Reply:* It’s tricky to understand, but the options object is optional. So your actual hook function could be the first or second arg to Before
*Thread Reply:* I need to double check in terms of arguments to the hook function.
In the “Hooks” section of the documentation Before() has the option to have a name passed in. The reference documentation for Before() doesn’t show that. Which of those is correct?
*Thread Reply:* Fixed the doc just now, thanks for pointing out. It’s an optional prop on the options object on both Before and After
We’re writing a testing framework. We want to test that our failures fail in the right ways. If the fail in the right ways, we want the tests to pass. Any ideas on how to achieve this without manipulating the scenario results object?
*Thread Reply:* Consider using setDefinitionFunctionWrapper - you can catch the error that results from the step, then decide if you want to rethrow or swallow it https://github.com/cucumber/cucumber-js/blob/main/docs/support_files/api_reference.md#setdefinitionfunctionwrapperwrapper
*Thread Reply:* I’m not sure that’ll do what we want. We want to throw it initially - fail the Step - but catch it in After() - pass the Scenario.
*Thread Reply:* I have a similar test, maybe it's not the best way but it works for me https://github.com/tim-yao/cucumber-nightwatch/blob/main/test/features/cucumber_nightwatch.feature
*Thread Reply:* I haven’t been able to find where your code is that implements those steps, @Tim Yao, though thank you for the example and I’m very interested to see that.
*Thread Reply:* Remember that I want the step to fail, but the scenario to pass. That means the failure has to happen in After()
*Thread Reply:* Sorry, I mean After() has to swallow up the failure - make sure the Scenario as a whole passes.
*Thread Reply:* Step definition can be found in https://github.com/tim-yao/cucumber-nightwatch/blob/main/test/features/cucumber_nightwatch.steps.js
*Thread Reply:* But I don’t want the failing step to pass. I want the failing step to fail. I then want the scenario to pass.
*Thread Reply:* Thank you for pointing me to the code you were talking about, though. I think it just doesn’t achieve what I want to achieve.
*Thread Reply:* The code I posted is exactly what you asked for. But I think you didn't read the code though. The test is testing the failure of a sub-process of another cucumber test. If it gets the failed test result, then it passes. However, you have to read the code then you can understand. It's quite hard to explain all the details.
*Thread Reply:* Wow, yeah, I didn’t understand the full context. I wasn’t really familiar with all of this stuff. Your clarification helped a lot, thank you.
*Thread Reply:* https://github.com/Tallyb/cucumber-playwright Have you tried this one?
With junit formatter and cucumber-js v9.3.0, we recently saw the below error intermittent in the console report. Any idea?
NaN scenarios
683 steps (8 failed, 63 skipped, 612 passed)
34m14.690s (executing steps: 48m28.393s)
/app/node_modules/@cucumber/cucumber/src/formatter/junit_formatter.ts:131
data.time = testStepResult.duration
^
TypeError: Cannot read properties of undefined (reading 'duration')
at JunitFormatter.getTestStep (/app/node_modules/@cucumber/cucumber/src/formatter/junit_formatter.ts:131:32)
at /app/node_modules/@cucumber/cucumber/src/formatter/junit_formatter.ts:101:19
at Array.map (<anonymous>)
at JunitFormatter.getTestSteps (/app/node_modules/@cucumber/cucumber/src/formatter/junit_formatter.ts:99:47)
at /app/node_modules/@cucumber/cucumber/src/formatter/junit_formatter.ts:221:28
at Array.map (<anonymous>)
at JunitFormatter.onTestRunFinished (/app/node_modules/@cucumber/cucumber/src/formatter/junit_formatter.ts:212:29)
at EventEmitter.<anonymous> (/app/node_modules/@cucumber/cucumber/src/formatter/junit_formatter.ts:83:14)
at EventEmitter.emit (node:events:525:35)
at EventEmitter.emit (node:domain:489:12)
I feel it may not related to junit though. The NaN scenarios was from default, right?
And the html report is also broken.
*Thread Reply:* I did a comparison with a working HTML report. The broken HTML report stops at before the testRunFinished part. Without continue output the rest of the HTML.
*Thread Reply:* Another different formatter error we got yesterday, after all test run finished:
/app/node_modules/@cucumber/cucumber/src/formatter/helpers/summary_helpers.ts:77
objects.forEach((x) => (counts[x.status] += 1))
^
TypeError: Cannot read properties of undefined (reading 'status')
at /app/node_modules/@cucumber/cucumber/src/formatter/helpers/summary_helpers.ts:77:36
at Array.forEach (<anonymous>)
at getCountSummary (/app/node_modules/@cucumber/cucumber/src/formatter/helpers/summary_helpers.ts:77:11)
at formatSummary (/app/node_modules/@cucumber/cucumber/src/formatter/helpers/summary_helpers.ts:53:23)
at PrettyFormatter.logSummary (/app/node_modules/@cucumber/cucumber/src/formatter/summary_formatter.ts:72:20)
at EventEmitter.<anonymous> (/app/node_modules/@cucumber/cucumber/src/formatter/summary_formatter.ts:27:14)
at EventEmitter.emit (node:events:525:35)
at EventEmitter.emit (node:domain:489:12)
at Coordinator.onWorkerProcessClose (/app/node_modules/@cucumber/cucumber/src/runtime/parallel/coordinator.ts:200:29)
at ChildProcess.<anonymous> (/app/node_modules/@cucumber/cucumber/src/runtime/parallel/coordinator.ts:158:12)
*Thread Reply:* Both HTML reports stoped at before the testRunFinished part.
Hello, Have another issue. Any coding experts, please assist. I'm launching multiple browsers to run tests and I notice that all browser launch correctly but the tests only run on the last browser in the configuration. Here is the code. I can describe in detail if anyone wants to huddle. Thanks in advance.
to reiterate, there are 5 diff browser configuration i the browserConfigs, and all of them launch correctly, but the tests only show running the very last config ( in this case, iPhone12 ). THanks.
```const browserConfigs = [ { name: 'Desktop chromium', type: chromium, device: devices['Desktop Chrome'] }, { name: 'Desktop firefox', type: firefox, device: devices['Desktop Firefox'] }, { name: 'Desktop safari', type: webkit, device: devices['Desktop Safari'] }, { name: 'Mobile Chrome Pixel 5', type: chromium, device: devices['Pixel 5'] }, { name: 'Mobile Safari iPhone 12', type: webkit, device: devices['iPhone 12'] }, ];
// Create a new browser context and page per scenario Before(async function ({ pickle }) { console.log("BEFORE new browser")
for (const config of browserConfigs) {
global.browser = await config.type.launch(options);
let contextOptions = { ...config.device };
global.context = await global.browser.newContext(contextOptions);
global.page = await global.context.newPage();
activeConfigs.push(config);
console.log(config.name)
}
});```
Hello, does anyone know if there is a way to let the test scenario continue even if one of the step fails in the scenario ?
*Thread Reply:* Hello in my opinion if you need it to continue the these are two separate scenarios. Maybe you should split them into smaller ones
Hi .I am facing a really odd issue when trying to execute my cucumber js project in pipelines.
Context : TS Project with Playwright + Cucumber JS - Target Web application
Issue :
• can run project locally no problem . Cucumber Js finds the support code and calls the hooks
• when trying to run on bitbucket , cucumber hooks are not called --- no error whatsover
What I have tried :
• enabled cucumber debugging .
◦ The trail stops after the log : Found support files to load via import based on configuration: [] ( Note , when it works locally , after this log ..the cucumber hooks are called )
My question :
• what can cause cucumber hooks to not be called ? ( from the output I can tell it sees the support code )
• why is it not happening when I run locally
• Is there any further debugging possible ?
• Anybody knows where in the cucumber lib I can check what should be called next
> cucumber-js features/home-page/home.feature
Configuration will be loaded from "cucumber.mjs"
No profiles specified; using default profile
Resolved configuration: {
backtrace: false,
dryRun: false,
forceExit: false,
failFast: false,
format: [
'json:reports/cucumber-report.json',
'html:reports/report.html',
'summary',
'progress-bar',
'@cucumber/pretty-formatter'
],
formatOptions: { snippetInterface: 'async-await' },
import: [],
language: 'en',
name: [],
order: 'defined',
paths: [ 'features/home-page/home.feature' ],
parallel: 0,
publish: false,
publishQuiet: true,
require: [ 'src/****/**.ts' ],
requireModule: [ 'ts-node/register' ],
retry: 1,
retryTagFilter: '',
strict: true,
tags: '',
worldParameters: {}
}
Found feature files based on configuration: [ '/workspace/features/home-page/home.feature' ]
Found support files to load via `require` based on configuration: [
'/workspace/src/support/hook.ts',
]
Found support files to load via `import` based on configuration: [
Hello All, I have a "Then" function with a timeout.... Then('The device will connect to network', { timeout: 15 * 60 * 1000 }, function () {..... inside that I need to periodically check status ....so I have used setInterval.(5 seconds).. for which the clearInterval() is done on certain condition... but when the cucumber timeout of 15 seconds occure,,,, ..the cearInterval() is not done ...so it keeps on coming back after 5 second ? Where to add clearInterval() which will be callled if timeout occurs
*Thread Reply:* You could set your interval id on the world (this) and then clear it from a AfterStep hook
*Thread Reply:* https://github.com/cucumber/compatibility-kit/blob/main/.github/workflows/release-ruby.yml#L36-L38
Hello All, If I have to repat a failed scenario , how can I achieve.... can I put number of repeatition ?
*Thread Reply:* You can https://github.com/cucumber/cucumber-js/blob/main/docs/retry.md
Hi everyone! I'm integrating Cucumber in an existing React app testing it with react-testing-library. It's working, but I'm having issues with some external libraries and I would like to know if anyone faced this kind of issue before and what you all can recommend to solve it. I'm searching about how I could mock libraries or React components but they all use Jest, is there a better approach for this or do you suggest go with Jest? (I was looking at the example provided in this comment).
Thank you all!
Salutations Earthling! "Guys" is easily replaced with the more gender-neutral "Folks" or "All". We'd appreciate if you tried to use that. Thanks!
Hi all, could you please help with this?
*Thread Reply:* Solution here: https://stackoverflow.com/questions/77356810/run-cucumber-by-tag-or-run-all-tests?noredirect=1#comment136374867_77356810
*Thread Reply:* Weird. We don’t have a config, but way back when we messed with the package.json script our tags didn’t give us problems. I’m not the one that wrote that code, though.
Hello,
I’m new to the community, and I apologize in advance if this topic has already been addressed (I couldn’t find it in the history). We use cucumber-js for very low-level tests for our services. We are on a TS stack.
We have a lot of scenarios that execute quickly (barely 500ms), but the loading time can take almost 2 minutes, whether we execute one or all scenarios. It’s not a huge issue, but it quickly becomes time-consuming during development.
Do you have any advice or tips for reducing this loading time? Or perhaps at least a solution for monitoring what’s happening during loading?
I haven’t found anything relevant while searching the web...
For example, on one of our services:
53 scenarios (53 passed)
264 steps (264 passed)
0m00.338s (executing steps: 0m00.210s)
Total executing time: 1m 36s
Thanks in advance.
*Thread Reply:* That’s odd!
Do you have any expensive setup operations that run in a BeforeAll hook or somewhere else?
*Thread Reply:* No particularly heavy pretreatment. We have beforeStep functions, but the execution time doesn’t seem to be affected. I feel that it’s more the compilation that takes time.
*Thread Reply:* Okay, it would be good to profile this to see where the time is going. I need a refresher on how best to do that in Node.js though!
*Thread Reply:* It’s definitely related to compilation, when I run with the environment variable TS_NODE_TRANSPILE_ONLY=true (so no compilation) I have a total execution time of 9s! But we lose a little the interest of TS if we generalize this…
I am very interested in having a view of what is happening in compilation, I have not found a solution yet.
*Thread Reply:* Ah interesting. Do you see that if you compile separately with tsc?
*Thread Reply:* For past projects I have set ts-node to transpile only but then added a build step in CI to compile with tsc as a compromise.
Without using cucumber runner, can run all the scenarios with playwright test runner
*Thread Reply:* I don’t think so unfortunately. Playwright would need a way to preprocess features into tests and it doesn’t have that as far as I can see.
For Cypress there is https://github.com/badeball/cypress-cucumber-preprocessor
Anyone help me Browserstack integration with Playwright using Typescript not Javascript
I have solution from browserstack with Js not Ts
https://github.com/browserstack/node-js-playwright-browserstack/tree/sdk
*Thread Reply:* Node.js executes JS code. Either you need to compile TS code into JS, or you need to use ts-node to execute TS code in runtime.
Hi Team i am facing an issue with cucumber hooks[i am using playwright with cucumber.js] i have defined the the playwright browser- context- page in cucumber before hook but this page object is not passing to .js file and not coming to steps file as well
I am thinking there is some setup i missing from cucumber hooks to regular playwright files
can some one help me here
*Thread Reply:* I probably don’t know enough to help, but you probably need to link to your code for anyone to really try to understand what’s going on.
Hi everyone!
I need help with passing a custom CLI argument to cucumber.
package.json:
"scripts": {
"pretest": "npx ts-node src/utils/report/reportInit.ts",
"test": "cucumber-js --config=configs/cucumber.cjs",
"posttest": "npx ts-node src/utils/report/reporter.ts",
},
I need to pass custom CLI argument and catch it in BeforeAll hook, then implement my solution.
When I try this:
npm run test --condition=true
I am not getting condition=true string inside arguments array (process.argv):
[
'C:\\Program Files\\nodejs\\node.exe',
'C:\\Users\\Jasurbek\\Documents\\Projects\\core-regression-bdd\\node_modules\\@cucumber\\cucumber\\lib\\runtime\\parallel\\run_worker.js'
]
Could you point me in the correct direction, please?
#help <#C6QJ6N695|help-cucumber-js>
*Thread Reply:* try npm run test -- --condition=true
https://stackoverflow.com/a/14404223
Hi,
I have a cucumber config:
{
formatOptions: {
snippetInterface: 'async-await'
},
paths: [
'src/features/'
],
dryRun: false,
require: [
'src/step_definitions/****/**.ts',
'hooks.ts'
],
requireModule: [
'ts-node/register'
],
format: [
'json:test-results/json-report.json',
'progress'
],
parallel: 5,
}
Before and BeforeAll hooks are executing functions in it 5 times (once per browser).
For example, I want to make a purchase before certain scenarios and those scenarios use that purchased product:
Before({ tags: '@purchasing', name: 'Display (Image) Campaign purchasing' }, async function(){
await purchaseCampaign('CPM', 'image', 'advertiser');
});
When I am running tests, I see each browser is purchasing a campaign/product. A total of 5 products were purchased. How can I manage so that hook actions are executed sequentially (and only once), not parallelly?
*Thread Reply:* Before hooks are always executed once per scenario.
BeforeAll hooks are executed once per test run in serial mode, or once per worker in parallel mode. Since you have parallel: 5 this will mean 5 times in practise. You could use BeforeAll without parallel, or (better) you could make your purchaseCampaign function idempotent so when called a 2nd, 3rd time etc it will just no-op since the record is already created.
*Thread Reply:* @David Goss How can I use BeforeAll without parallel? I can only set timeout for BeforeAll. Are there other ways I am missing? The credentials from the AWS Parameter store are being retrieved 5 times. And the campaign was also purchased 5 times, but I need it to be purchased once. I'd appreciate your help.
*Thread Reply:* If you want the BeforeAll only run once, you need to not use parallel
*Thread Reply:* or as mentioned, have it do some sort of halting execution.
create unless already_created? so to speak
*Thread Reply:* Is there any way to make BeforeAll hook run once? Like, maybe some passing environment variables?
*Thread Reply:* Some environment variables get set by Cucumber on the worker processes, see https://github.com/cucumber/cucumber-js/blob/main/docs/parallel.md
So, you could do something like if (process.env.CUCUMBER_WORKER_ID === '0') to make your thing only run on the first worker.
But as noted previously, making your setup functions of a “create if not exists” nature will give you a better time in the long run.
When a test fails, is there a way to save its failure (with some unique information that identifies that particular Scenario and attempt) in the After hook and then use this unique info in the Before hook to tell that it’s a retry of that same scenario?
*Thread Reply:* If you want to retry failed tests, you can take look at this part of documentation: https://github.com/cucumber/cucumber-js/blob/main/docs/retry.md
*Thread Reply:* I already retry failed tests. I want more information about the failed tests when a new test runs.
*Thread Reply:* You can create an object or an array. Then push the result of the scenario to that object or an array. Or you can also write results to json file so that you read it after runtime.
*Thread Reply:* Sorry if I’m off base here, but what part of that is the unique id for the Scenario that I’d be able to connect to a later attempt?
*Thread Reply:* I need to be able to recognize in the retry that the current retry is connected to that specific failed scenario.
*Thread Reply:* You can’t do this at the moment. I am going to be re-looking at retry though with a view to making it a more generic extension point where you can plug in your own retry logic.
What kind of context would you want to pass from the failed attempt to the next attempt, out of interest?
*Thread Reply:* Good question and hard to answer because I haven’t gotten to experiment with anything. In my specific instance, I’d want the random seed I’d created in that previous Scenario. To generalize that, maybe what I want is to be able to communicate between tests. I suppose I might be able to use the global scope for that. It would help with retries, but even in parallel tests, could see this kind of info being useful as input for all running tests. For example, I have one case where if one test with a specific tag fails, none of the other tests that have that tag should be run either because they’re all going to fail and it wastes a lot of time. Maybe these things really are something for me to handle in the global scope somehow. Is that possible? And does that global scope exist for parallel tests too? I have to admit I haven’t tried those yet.
If I were trying to brainstorm more generally, for retries specifically people might want the info from the scenario that failed. That might be enough for most people.
hello. I am new to Cucumber. I am trying to set it up in an React Typescript project in combination with Jest for rendering the components. Can someone please help me with the config? I cannot make .ts step_definitions files work, neither integrate it with Jest. Any response is appreciated. Thanks 😁
*Thread Reply:* Why do you want both Cucumber and Jest? They’re both test runners but you can only really use one of those at a time
*Thread Reply:* > in combination with Jest for rendering the components If you want the part that renders a React component, that’s not Jest doing that. It’s maybe testing-library with a JSDOM environment, or something similar. You should be able to use that within Cucumber step definitions.
Hey,
I need your help with skipping tests with certain tags, for example: @bug
Here's a command to run test in package.json: cucumber-js --config=configs/cucumber.cjs --profile ci
But tests run on docker on ci/cd pipeline: Attaching error log from docker.
On, my terminal tags are being parsed just fine. Am I missing something?
Is this a correct command to run all tests except with tag bug: cucumber-js --config=configs/cucumber.cjs --profile ci --tags "not @bug" ?
*Thread Reply:* In your docker compose command you have
--build-arg TAGS="-- --tags "not @bug""
As your usage is enclosed in double quotes, you may need to escape the inner ones that wrap your tag expression.
*Thread Reply:* @David Goss Need your help here again. When I run tests by tag with this command locally it worked fine:
cucumber-js --config=configs/cucumber.cjs --profile ci --tags "@3 and @4 and @5"
But when I ran exactly the same command from Jenkins, it did not work. Tags are passed as arguments to docker. Docker image is created in Linux ec2 instance. I've been trying to solve this issue for more than a month already, but no luck. Could you enlighten me, please?
Hi everyone! I am using Cucumber version 10.3.1. I need to periodically clean up data the tests create during the run time. When I try to call the functions in the project from the terminal I get the error (pls see the attachment). Cucumber is not installed globally. I use it only for the project. How can I fix it? Thanks in advance!
*Thread Reply:* You see that error because your file is calling setDefaultTimeout, but you’re only supposed to do that when an actual test run is happening.
If you split out your cleanup functions into another file that doesn’t call any Cucumber functions, and then run that, you should be fine.
*Thread Reply:* The cleanup function is in another folder:
Project folder:
|-> hook.ts // This is where setDefaultTimeout is.
|-> src
|-> utils
|-> clearData.ts
clearData.ts has few imports but none of them are related to Cucumber (either step definitions or POMs).
clearData.ts:
```import { AxiosError } from 'axios';
import { DashboardPayload } from '../payloads';
import { httpRequest } from './api/httprequest/httpsRequest';
import { ListOfCampaigns } from './interfaces';
import { RequestBuilder } from './api/httprequest/RequestBuilder';
import { logger } from './logger/logger';
export async function deleteDraftCampaigns() { const { url } = DashboardPayload.search.admin; const config = new RequestBuilder() .setUrl(url) .setMethod('GET') .setCookies('admin');
const { data: { data: listOfCampaigns } } = await httpRequest<ListOfCampaigns>(config);
logger.info(Found ${listOfCampaigns.length} campaigns);
const filteredCampaigns = listOfCampaigns.filter(campaign => campaign.campaign_status === 'draft' && campaign.name.includes('Test Automation'));
logger.info(${filteredCampaigns.length} campaigns selected for deletion);
if (filteredCampaigns.length > 0) {
for (const campaign of filteredCampaigns) {
const deleteRequest = new RequestBuilder()
.setUrl(/api/campaign/${campaign.id}/delete)
.setMethod('POST')
.setCookies('admin');
try {
const { status } = await httpRequest(deleteRequest);
<a href="http://logger.info">logger.info</a>(`Deleting campaign ${campaign.id}... status ${status}`);
} catch (error) {
const err = error as AxiosError;
if (err.status! >= 500) {
<a href="http://logger.info">logger.info</a>(`Deleting campaign ${campaign.id}... status ${err.status}`);
}
}
}
} else { logger.info('No campaigns for deletion'); } }```
*Thread Reply:* The stack trace shows your hooks.ts file being executed
*Thread Reply:* Same applies to all cucumber functions, you see it has highlighted BeforeAll now
Hi everyone!
Could you help debug this issue, please? When I run a test by tag from Jenkins (on Linux ec2 instance) I have an issue with BeforeAll hook that was supposed to get credentials from the AWS Parameter Store and instantiate an object from ParameterStore class. Locally, it is working as it is expected.
The full log from Jenkins is attached. I am confused about what's really causing the problem. Is it the usage of quotes in config formatter or BeforeAll hook isn't invoked when tag is passed? or anything else?
*Thread Reply:* The message re formatter notation is only a warning and isn’t related to the error you have below it. Seems like a hook or step issue.
In my Before step, I log the Scenario name, but it doesn’t work for the first Scenario. Why is that and how can I get it to work?
*Thread Reply:* When you say log, are you doing this.log (which emits a plain text attachment to formatters) or like console.log?
*Thread Reply:* console.log. I didn’t know this.log was a thing. Also, console.log gets things to appear in the GitHub actions console [while the action is running].
*Thread Reply:* I suspect console.log() is async. Despite that, it works well for all the Scenarios after the first one.
*Thread Reply:* Let’s try and put together a minimal repro. Can you share the code from that Before hook?
*Thread Reply:* Great idea, not sure why I didn’t think of it, though I’m not sure we can use my code for that. Maybe a fresh repo. These are the relevant lines.
*Thread Reply:* Is there an example of, say, the simplest repo ever? With a github action to run the tests? If so, I could fork that and try to recreate there.
Does cucumber.js log the test results asynchronously? I’ve added my own logs and in my GitHub action, some of the logs get cut off sometimes [including the final cucumber logs]. [There are more details in this GitHub community post]
I’m having a puppeteer problem, but I’m not sure where else to look for help. I’m running cucumber and puppeteer in something called a “background action” on a server. Something is leaving behind headless chrome browsers, taking up a lot of server memory over time. I think sometimes the process gets interrupted in the middle and the browser doesn’t get a chance to close. Does someone have ideas about what I can do about this? I don’t want to automatically kill all browser processes in case the user has some of their own. Is there a way I can get and store the browser PID so that later I can close the right one(s)?
*Thread Reply:* I found a stackoverflow suggesting to use try {...} catch () {...} finally { await browser.close() }, but I’m not sure how to do that with cucumber. Would I put this in the Before() function, where I first open the browser? Do I put it in the After() somehow? Would that even help?
Hi everyone! Is it possible to create/register new keywords in cucumber-js? Like IF, ELSE, BUT, etc?
*Thread Reply:* But you can use today in your feature files (works the same as And)
*Thread Reply:* If and Else would be control flow, that’s not something that will ever be added to the syntax
*Thread Reply:* what about other custom keywords? Is it possible to add/register them myself?
*Thread Reply:* Just wanted to insert my custom keywords, if possible, to make scenarios look good.
*Thread Reply:* This sounds like connextra documenting that can be done in between feature and your first scenario invocation.
Here you can write any words you want. Maybe that will help ?
*Thread Reply:* ```Feature: Eating cucumbers
It is well known that cucumbers count as one of your five a day but what people don't often think of is that a cucumber salad if made correctly can be very tasty
As a healthy eating enthusiast I want to provide a quick and easy way for people to see recipes for cucumbers So that I am able to encourage more people to cook and prepare meals with cucumbers And I am able to make more money selling my cookbooks.
Scenario: .......
Rule: Cucumbers can be grown in cold climates Scenario: ......```
Hi guys, I have created a data table with two fields portfolio title and artist fullname. On my step definitions file, I have implemented the same. However, the issue I am getting is that
porfolioTitle = Portfolio artistFullName = Dummy Artist New
Do you know why this is happening and how I can solve this?
*Thread Reply:* Additionally I noticed that if portfolioTitle has single word, then the application works well but if portfolioTitle has multiple words then I get the above error.
*Thread Reply:* First, can you show us what the Scenario Outline itself looks like? Also, did you copy/paste anything into this Examples table any point? I've seen weird things like this happen before with zero-width spaces from webpages, you can't see them but they can cause real havoc. Maybe try deleting the whole Examples section and re-type it, then see if it still behaves the same way.
*Thread Reply:* I would recommend writing your step definition like this: "enters value in the respective field with {string} {string}" and then there would be double quotes around each parameter like this in your feature file:
Then enters value in the respective field with "<artistFullName0>" "<portfolioTitle>"
It's the step definition where your parsing is getting messed up.
*Thread Reply:* Thank You @Steven Hunt . I added double quotes and “{string}” in the step definition file as well and it worked.
*Thread Reply:* Quick tip here: You used examples, not data tables. Data table values are passed as a 2D array to the last parameter of the anonymous function of the step definition.
Then I check the following data
| First name | John |
| Last name | Smith |
Step definition:
Then('I check the following data', function(dataTable) {
const rows = dataTable.raw();
// [ ['First name', 'John'], ['Last name', 'Smith'] ]
});
Salutations Earthling! "Guys" is easily replaced with the more gender-neutral "Folks" or "All". We'd appreciate if you tried to use that. Thanks!
Hi , need help to solve this problem while running the feature scenario
Attempt 4 failed: Error: Cannot attach when a step/hook is not running. Ensure your step/hook waits for the attach to finish.
(node:2685) UnhandledPromiseRejectionWarning: Error: Cannot attach when a step/hook is not running. Ensure your step/hook waits for the attach to finish.
*Thread Reply:* If you've async function that takes a screenshot or records a video and then attaches it, most likely it is the cause. I had a similar issue, and resolved it by adding setTimeout after async function.
Has anyone successfully integrated CucumberJS with Qase. I know Qase has a reporter library that supports it https://github.com/qase-tms/qase-javascript/tree/master/qase-cucumberjs#readme but it seems to be broken
Hi everyone!
I need help with the cucumber configuration. I am using an Allure reporter and progress to print the progress of the test to the console. The issue is if I put the allure reporter on the 0th index of the format , cucumber doesn't pass info to the allure but prints on the console. If I put allure reporter on the 1st index, allure collects test data, and a report is generated but progress doesn't print on the console.
*Thread Reply:* From the allure-cucumber-js readme:
> If you want to retain default formatter add some dummy file as output:
So you want to do something like:
format: [
'progress',
[`file://{path.resolve(__dirname, 'allureReporter.cjs')}`, './dummy.txt']
]
This will direct progress output to the terminal, and then a no-op file will accept the allure output while it does its normal thing.
*Thread Reply:* (I’m not a user of allure so anything beyond this, you would need to consult that project.)
*Thread Reply:* Docs on how to specify formats in the config (which has changed a bit hence the nested array in my example there) https://github.com/cucumber/cucumber-js/blob/main/docs/formatters.md
Hey all! Is it possible to re-use certain scenarios as a step definition? For example: ```Scenario: Performs some group of actions When I do action 1 And I do action 2 And I do action 3 Then I check all actions are done
Scenario: Another test Given Performs some group of actions And I do action 4```
*Thread Reply:* No, but you might find Background useful https://cucumber.io/docs/gherkin/reference/#background
Hello All, is there any known issue of cucumber-nodejs in running all feature files together vs running them individually ?
Because we are getting test failure if we run all together and not getting failure if we run them individually.
We have cucumber-nodjs running on linux on Rasberi pi which is using usbserial interface.
If we use "npm run test" to run compelte suite, randomly we are getting problem in usbserial communication. If we use "npm run fatures/xyz.feature then things go smoothly!
Are we missing anything here ? one more information is in beforehooks our library which needs the usbserial binds and in afterhooks it unbinds,
*Thread Reply:* Hard to say without more details, but usually this is a signal that your scenarios aren’t fully independent and are competing for a resource. It sounds like you have Before and After hooks to setup and teardown resources though which is the right pattern. Are you using the parallel mode?
*Thread Reply:* Thanks David. No we are not using the parallel mode.
*Thread Reply:* > one more information is in beforehooks our library which needs the usbserial binds and in afterhooks it unbinds
Could this be causing an issue if you are binding and unbinding multiple times in a single process? You might consider using BeforeAll and AfterAll instead if it’s applicable
I am getting a webpack compilation error in Cucumber and Cypress. Anyone here that can help me ?
*Thread Reply:* Error: Webpack Compilation Error
Module parse failed: Unexpected token (3:5)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See <https://webpack.js.org/concepts#loaders>
| Feature: Analytics
| Scenario: SingleDownload
> When the user is in A&D page
| Then perform single download
at Watching.handle [as handler] (/Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-preprocessor/dist/index.js:212:23)
at /Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:303:9
at Hook.eval [as callAsync] (eval at create (/Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:18:14)
at Watching._done (/Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:299:28)
at /Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:213:21
at Compiler.emitRecords (/Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:919:5)
at /Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Watching.js:191:22
at /Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:885:14
at Hook.eval [as callAsync] (eval at create (/Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:18:14)
at /Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:882:27
at /Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/neo-async/async.js:2818:7
at done (/Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/neo-async/async.js:3522:9)
at alreadyWritten (/Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:714:8)
at /Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:802:19
at /Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/node_modules/graceful-fs/graceful-fs.js:123:16
at /Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:123:16
at /Users/atul/Library/Caches/Cypress/13.8.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/graceful-fs/graceful-fs.js:123:16
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read/context:68:3)
*Thread Reply:* This means that you haven't configured webpack properly. I recommend looking at any of the webpack examples at https://github.com/badeball/cypress-cucumber-preprocessor/tree/master/examples
Hi everyone! I run 5 tests in parallel. There are 13 scenarios in the feature file. I want to run the last scenario (which is at the end of the feature file) to run only after other scenarios are run. How can I make it wait until other scenarios are finished running?
Hi everyone! I run 5 tests in parallel. At the beginning, test run in 5 different browsers, and then at some point test won't run parallelly, but only one test at a time is executed. Do you know why cucumber switches to executing tests one by one?
*Thread Reply:* Most definitely not. There are retries tags on few scenarios only.